我在项目中使用libmysql,我总是看到确切的泄漏摘要仍然可以访问:21块中的73,944字节'每次在Valgrind,都不应该在那里。后来我从这个link:
测试了这个示例程序/* Simple C program that connects to MySQL Database server*/
#include <mysql.h>
#include <stdio.h>
main() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
char *password = "PASSWORD"; /* set me first */
char *database = "mysql";
conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, server,
user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
/* send SQL query */
if (mysql_query(conn, "show tables")) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
res = mysql_use_result(conn);
/* output table name */
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
printf("%s \n", row[0]);
/* close connection */
mysql_free_result(res);
mysql_close(conn);
}
当我和Valgrind一起跑步时,我仍然得到:
==22556== LEAK SUMMARY:
==22556== definitely lost: 0 bytes in 0 blocks
==22556== indirectly lost: 0 bytes in 0 blocks
==22556== possibly lost: 0 bytes in 0 blocks
==22556== still reachable: 73,944 bytes in 21 blocks
==22556== suppressed: 0 bytes in 0 blocks
答案 0 :(得分:1)
&#34;仍然可以到达&#34;并不意味着存在问题。来自horse's mouth:
&#34;仍然可以到达&#34;意味着你的程序可能没问题 - 它没有免费 它可能有一些记忆。这很常见,而且往往是合理的。 如果您不想看到这些报告,请不要使用--show-reachable = yes。
答案 1 :(得分:0)
之后
mysql_close(conn);
致电:
mysql_library_end()