Valgrind:libmysql 示例程序给出“仍然可达:"泄漏 [英] Valgrind: libmysql example program gives 'still reachable:' leak

查看:21
本文介绍了Valgrind:libmysql 示例程序给出“仍然可达:"泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个项目中使用 libmysql,每次在 Valgrind 中,我总是看到确切的泄漏摘要仍然可以访问:21 个块中的 73,944 字节",这不应该存在.后来我从这个链接:

I was using libmysql in a project and I always see the exact leak summary 'still reachable: 73,944 bytes in 21 blocks' every time in Valgrind, which shouldn't be there. Later I tested this sample program from this 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 运行这个时,我仍然得到:

When I run this with Valgrind, I'm still getting:

==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

  1. 这是否值得担心?
  2. 这是 libmysql 中的错误吗?

推荐答案

仍然可以访问"并不意味着存在问题.来自马嘴:

"Still reachable" doesn't mean that there is a problem. From the horse's mouth:

仍然可以访问"意味着你的程序可能没问题——它不是免费的它可能有一些记忆.这是很常见的,而且通常是合理的.如果您不想看到这些报告,请不要使用 --show-reachable=yes.

"still reachable" means your program is probably ok -- it didn't free some memory it could have. This is quite common and often reasonable. Don't use --show-reachable=yes if you don't want to see these reports.

这篇关于Valgrind:libmysql 示例程序给出“仍然可达:"泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆