我在项目中使用libmysql,每次在Valgrind中,每次都能看到确切的泄漏摘要“仍然可以到达:73,944字节,共21个块”,这不应该存在。后来我从[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
“仍可访问”并不表示存在问题。从horse's mouth:
“仍可访问”表示您的程序可能还不错-它不是免费的它可能有一些记忆。这是很常见的且通常是合理的。如果您不想看到这些报告,请不要使用--show-reachable = yes。
之后
mysql_close(conn);
电话:
mysql_library_end()