سؤال

As a malloc wrapper, I use this classical snippet of code:

#define _GNU_SOURCE
#include <stdio.h>
#include <stdint.h>
#include <dlfcn.h>

void* malloc(size_t size)
{
    static void* (*real_malloc)(size_t) = NULL;
    if (!real_malloc)
        real_malloc = dlsym(RTLD_NEXT, "malloc");

    void *p = real_malloc(size);
    fprintf(stderr, "malloc(%d) = %p\n", size, p);
    return p;
}

Valgrind is upset because there are buffers still allocated by dlsym at the end of the program.

==32691== 32 bytes in 1 blocks are still reachable in loss record 1 of 1
==32691==    at 0x4C279FC: calloc (vg_replace_malloc.c:467)
==32691==    by 0x528559F: _dlerror_run (dlerror.c:142)
==32691==    by 0x5285099: dlsym (dlsym.c:71)
==32691==    by 0x4060BC: malloc (memory.c:222)

How can I release those resources ? Thanks

هل كانت مفيدة؟

المحلول

1 blocks are still reachable

These blocks are just fine. You don't need to worry about them, they are not leaks. There is nothing to see here, move along.

It's the "definitely lost" that you should care about.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top