我用"valgrind --leak-check = full"测试了我的软件,它显示:
==90862== 7,627 bytes in 4 blocks are definitely lost in loss record 858 of 897
==90862== at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==90862== by 0xD64991C: concat(int, ...) (Client.cpp:150)
Run Code Online (Sandbox Code Playgroud)
我无法理解为什么,因为我在calloc之后使用free().这是我的代码:
char* p = concat(2, buffOld, buff);
char *x;
while(true) {
x = p;
p = strstr(p,"\\final\\");
if(p == NULL) { break; }
*p = 0;
p+=7;
parseIncoming((char *)x,strlen(x));
}
free(p);
Run Code Online (Sandbox Code Playgroud)
而"concat"功能:
char* concat(int count, ...)
{
va_list ap;
int i;
// Find required length to store merged string …Run Code Online (Sandbox Code Playgroud)