1

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

ziu
  • 2,634
  • 2
  • 24
  • 39
  • 1
    Maybe I am missing something here, and I don't know if it's even possible to release this buffer, but I would just ignore it. The dlsym buffer will be released when the program exits, and you need it as long as the program is running. – Thomas Padron-McCarthy Mar 19 '12 at 17:39
  • It does not bother me either, I am just curious. – ziu Mar 19 '12 at 17:41
  • Ok. Do you call dlclose? Does this buffer still remain? – Thomas Padron-McCarthy Mar 19 '12 at 17:43
  • I did that, but I only got an assertion failure `Inconsistency detected by ld.so: dl-close.c: 719: _dl_close:assertion `map->l_init_called' failed!` – ziu Mar 19 '12 at 17:45

1 Answers1

0

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.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362