小编Mon*_*ona的帖子

使用calloc和free后内存泄漏?

我用"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)

c valgrind memory-leaks

0
推荐指数
1
解决办法
1301
查看次数

标签 统计

c ×1

memory-leaks ×1

valgrind ×1