libipfwc memory leak?
Hi people!
I know that this letter is not for this mailllist. But I'm tired to find mistake.
I just writen this smal code for example:
--- cut ---
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include "libipfwc/libipfwc.h"
int main( int argc, char **argv)
{
pid_t pid;
unsigned int num_chains;
unsigned int num_rules;
static struct ipfwc_fwchain *chains;
struct ipfwc_fwrule *rules;
pid=fork();
if ( pid == -1 ) { printf("Can't fork!\n"); exit(0); }
if ( pid != 0) exit(0);
setsid();
while(1)
{
chains=ipfwc_get_chainnames(&num_chains);
rules=ipfwc_get_rules(&num_rules,0);
sleep(1);
}
return 0;
}--- end ---
When program is runnig I just type command "ps aux" and I saw that my program get more and more system memory.
Is this memory leak of libipfwc library?
In libipfwc.c function ipfwc_get_chainnames & ipfwc_get_rules use malloc() but not use free(). It's maybe ok for program ipchains but in my case is not gut.
How to fix it?
THANKS IN ADVANCE.
Signature · 4 lines
Andriy T. Yanko [email protected] * Avoid The Gates of Hell use Linux
Quoted 6 lines · Andriy T.Yanko
Hi people!
In
libipfwc.cfunctionipfwc_get_chainnames&ipfwc_get_rulesusemalloc()but not usefree(). It's maybe ok for program ipchains but in my case is not gut.How to fix it?
You have to free the structures yourself. If the functions themself freed the structures, they would not be able to return anything. This is not an error in libipfwc.
Regards
Anders Fugmann