Re: Memory leak ?

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

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){

    /* 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
    return 0;

and valgrind reports:

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 and .


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