tevent_context_init will cause memory leak when program exit.

Galen(liugang) galen.gang.liu at gmail.com
Sun Dec 30 21:30:29 MST 2012


Hi All:

In tevent-0.9.17/tevent.c +248 of tevent-0.9.17.tar.gz
tevent_backend_init malloc some memory block, but didn't free them when
program exit.


/*
  create a event_context structure. This must be the first events
  call, and all subsequent calls pass this event_context as the first
  element. Event handlers also receive this as their first argument.
*/
struct tevent_context *tevent_context_init_byname(TALLOC_CTX *mem_ctx,
                          const char *name)
{
    struct tevent_ops_list *e;

    tevent_backend_init();


This is my test file:

#include <stdio.h>
#include <talloc.h>
#include <tevent.h>

int main(int argc, char *argv[])
{
        struct tevent_context *event_ctx;

        event_ctx = tevent_context_init(talloc_autofree_context());
        if (event_ctx == NULL) {
                printf("The event context initialiaziton failed\n");
                return 1;
        }

        return 0;
}



gcc -o tevent_test2 tevent_test2.c -ltevent -ltalloc
valgrind ./tevent_test2

==19041== HEAP SUMMARY:
==19041==     in use at exit: 320 bytes in 5 blocks
==19041==   total heap usage: 8 allocs, 3 frees, 552 bytes allocated
==19041==
==19041== LEAK SUMMARY:
==19041==    definitely lost: 0 bytes in 0 blocks
==19041==    indirectly lost: 0 bytes in 0 blocks
==19041==      possibly lost: 320 bytes in 5 blocks
==19041==    still reachable: 0 bytes in 0 blocks
==19041==         suppressed: 0 bytes in 0 blocks


-Galen


More information about the samba-technical mailing list