这是个Mysql的内存泄漏吗

txwcan999 2008-03-25 07:06:52
我做了个简单的测试, 向问下是否是Mysql内存泄漏问题, 还是Valgrind的问题?

Linux机器配置:Linux localhost.localdomain 2.6.21-1.3194.fc7 #1 SMP Wed May 23 22:47:07 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux
Mysql : mysql 6.0.0-alpha
Valgrind: valgrind-3.3.0




1. 首先只写一个"Hello World"的测试文件test.cpp

#include </usr/local/mysql/include/mysql/mysql.h> //mysql header
#include <iostream>
using namespace std;

int main(void)
{
return 0;
}//end


编译时加入Mysql LIB库, 引用头文件, 生成test。
g++ test.cpp -Wall -o test -L"/usr/local/mysql/lib/mysql" -lmysqlclient \
-L "/usr/local/mysql/lib/mysql" -lmysqlclient_r -lm -lz ## -L "./lib" -ldbug

test是生成的可执行文件

2.用valgrind工具检测
valgrind --tool=memcheck --leak-check=full --show-reachable=yes -v -q ./test

//发现有一处内存问题

==2405== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 5 from 1)
==2405== malloc/free: in use at exit: 4,436 bytes in 1 blocks.
==2405== malloc/free: 1 allocs, 0 frees, 4,436 bytes allocated. <------------Look here
==2405== For counts of detected errors, rerun with: -v
==2405== searching for pointers to 1 not-freed blocks.
==2405== checked 920,248 bytes.
==2405==
==2405== 4,436 bytes in 1 blocks are still reachable in loss record 1 of 1
==2405== at 0x4A04CBF: calloc (vg_replace_malloc.c:279)
==2405== by 0x3A808D21DF: monstartup (in /lib64/libc-2.6.so)
==2405== by 0x40141B: __gmon_start__ (in /project/txw/TestValgrind_mysql_loaddata/test)
==2405== by 0x3A7FC032F1: (within /lib64/libresolv-2.6.so)
==2405==
==2405== LEAK SUMMARY:
==2405== definitely lost: 0 bytes in 0 blocks.
==2405== possibly lost: 0 bytes in 0 blocks.
==2405== still reachable: 4,436 bytes in 1 blocks.
==2405== suppressed: 0 bytes in 0 blocks.
Profiling timer expired

3. 当我将Mysql库, 头文件去掉后,重新make , 用Valgrind检查, 则没有这个问题。

请教各位大大!!!!!


...全文
159 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
txwcan999 2008-04-14
  • 打赏
  • 举报
回复
今天运行程序, 发现上面的问题没有了,但是不知道问题出在啦?可能是环境的问题, 可是Linux, Mysql都没有重装。

下面是我运行的一个程序的LOG, 可以看到malloc/free有关内容都释放了。

[root@localhost mysql_api-4-10]# make valgrind
valgrind --tool=memcheck --leak-check=full --show-reachable=yes -v -q ./mainapi
==16462== Memcheck, a memory error detector.
==16462== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==16462== Using LibVEX rev 1804, a library for dynamic binary translation.
==16462== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==16462== Using valgrind-3.3.0, a dynamic binary instrumentation framework.
==16462== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==16462== For more details, rerun with: -v
==16462==

K_Database(): mysql_library_init() [success]

connect [Success]

ping
len: 1 1 len: 12 61 61 61 67 67 67 67 67 67 67 67 67 len: 3 man


~K_Database(): mysql_library_end()

==16462==
==16462== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 1)
==16462== malloc/free: in use at exit: 0 bytes in 0 blocks.
==16462== malloc/free: 206 allocs, 206 frees, 114,004 bytes allocated.
==16462== For counts of detected errors, rerun with: -v
==16462== All heap blocks were freed -- no leaks are possible.
[root@localhost mysql_api-4-10]#
txwcan999 2008-03-29
  • 打赏
  • 举报
回复
难道各位大大开发的时候没有这个问题?

无人问津啊
  • 打赏
  • 举报
回复
应该是吧
不过这些泄露忽略吧
tangx100 2008-03-27
  • 打赏
  • 举报
回复
不明白 帮顶

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧