Re: Memory leak ?



On Fri, 15 Aug 2014 14:50:25 +0200
Alain Meunier <deco33 hotmail fr> wrote:
Hello,

I have the fllowing prog which leaks. I removed all the irrelevant
parts. Different functions call lead to memory leaks :

#include <stdlib.h>
#include <stdio.h>
#include <libgtop-2.0/glibtop.h>
#include <libgtop-2.0/glibtop/netload.h>
#include <libgtop-2.0/glibtop/close.h>

int main(int argc, char ** argv){

    glibtop_init();
    /* GET NET USAGE */
    glibtop_netload buf;
    const char interface[] = "wlan0";

    glibtop_get_netload(&buf, interface);

    printf("NETWORK :%lu %lu\n", buf.packets_in, buf.packets_out);

    // Just in case
    g_free(&buf);
    glibtop_close();
    return 0;
}

and valgrind reports:
[snip]

Any idea how I can fix it ?

First you need to establish that it is a memory leak.  It probably
isn't.  Since the memory is still reachable, it is probably just memory
allocated once on initialization and not freed on program close down,
in which case you need to use a valgrind suppressions file or just
ignore reports of still reachable "leaks", or you may be seeing the
gslice memory cache in use.

Try doing your test multiple times in a loop and see if that increases
memory usage and the number of reported leaks.  Note also the G_SLICE
environmental variable and its 'always-malloc' setting, the G_DEBUG
environmental variable and its 'gc-friendly' setting, and
https://wiki.gnome.org/Valgrind and
http://www.linuxprogrammingblog.com/using-valgrind-to-debug-memory-leaks .

Chris


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]