我最近一直通过Valgrind运行我的一个应用程序,但是有一些MYSQL相关的泄漏我无法解决.我把违规代码放在最基本的形式并测试了; 我得到了同样的泄漏.我应该忽视它们还是我做错了什么?
码:
#include <stdio.h>
#include <stdlib.h>
#include <mysql/mysql.h>
int main()
{
MYSQL *MYSQLIns;
MYSQLIns = mysql_init(NULL);
mysql_real_connect(MYSQLIns, "localhost", "username", "password", "database", 0, NULL, 0);
mysql_close(MYSQLIns);
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
编译:
gcc -g -lmysqlclient mysql_mem_test.c -o mysql_mem_test
Run Code Online (Sandbox Code Playgroud)
Valgrind输出:
valgrind --leak-check=full ./mysql_mem_test
==4601== Memcheck, a memory error detector
==4601== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==4601== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info
==4601== Command: ./mysql_mem_test
==4601==
==4601==
==4601== HEAP SUMMARY:
==4601== in use …Run Code Online (Sandbox Code Playgroud) 我一直试图让这个工作好几个小时,但我似乎无法理解它.
我正在尝试编写一个能够返回字符串数组的函数.
#include <stdio.h>
#include <stdlib.h>
/**
* This is just a test, error checking ommited
*/
int FillArray( char *** Data );
int main()
{
char ** Data; //will hold the array
//build array
FillArray( &Data );
//output to test if it worked
printf( "%s\n", Data[0] );
printf( "%s\n", Data[1] );
return EXIT_SUCCESS;
}
int FillArray( char *** Data )
{
//allocate enough for 2 indices
*Data = malloc( sizeof(char*) * 2 );
//strings that will be stored
char …Run Code Online (Sandbox Code Playgroud) 我已经使用PHP大约4年了,但是我遇到了一个问题需要稍微(:P)更好的性能,所以我选择了C++.
我正在编写的程序是一个Linux守护程序,它将扫描MySQL数据库以加载URL,使用cURL加载它们,搜索指定的字符串,然后相应地更新数据库.我面临的问题是我不知道需要存储在变量中的数据大小,以便搜索特定的字符串.
我想到了使用链表并在数据填充列表时分配更多节点.这是一个做事的好方法吗?
提前致谢,
我正在编写一个多线程程序,需要能够检查行是否需要更新并相应地执行操作.
我在使用MySql的内置日期/时间函数时遇到了问题,因此决定只将"lastupdate"时间戳存储为表中的整数.但是,我在将此时间戳转换为time_t时遇到问题,因此我可以使用时间函数.
任何帮助是极大的赞赏.
我遇到了realloc函数的问题.我只使用C(因此没有向量)与LibCurl.我遇到的问题是我在write_data函数的第12次迭代中得到以下错误(realloc():无效的下一个大小)(我将函数作为回调传递给Curl,每次libcurl都调用它时一些要传回的数据(数据以块的形式传递)).
-Removed-
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
#include <string.h>
char * Data; //stores the data
size_t RunningSize;
int write_data( char *ptr, size_t size, size_t nmemb, void *stream )
{
size_t ThisSize = (size * nmemb); //Stores the size of the data to be stored
size_t DataLen = strlen( Data ); //length of the data so far
RunningSize = (RunningSize + ThisSize ); //update running size (used as new size)
Data = realloc( Data, RunningSize ); //get new …Run Code Online (Sandbox Code Playgroud)