Hello Bytes,
I am using getifaddrs from ifadddrs.h on Debian Linux (Lenny).
Im using valgrind to check for memory leaks in my program. It seems that I have a memory leak in the code below but I cant figure out how to fix it. I thought i was freeing the address structure right but no luck.
If I do not run the loop and call "ifAddrStru ct = ifAddrStruct->ifa_next;" I don't get a memory leak but it also destroys the functionality of my method.
Any thoughts?
I am using getifaddrs from ifadddrs.h on Debian Linux (Lenny).
Im using valgrind to check for memory leaks in my program. It seems that I have a memory leak in the code below but I cant figure out how to fix it. I thought i was freeing the address structure right but no luck.
If I do not run the loop and call "ifAddrStru ct = ifAddrStruct->ifa_next;" I don't get a memory leak but it also destroys the functionality of my method.
Any thoughts?
Code:
#include <ifaddrs.h> // Used for getting local address
struct ifaddrs * ifAddrStruct = NULL;
getifaddrs(&ifAddrStruct);
while (ifAddrStruct != NULL) {
if (ifAddrStruct->ifa_addr->sa_family == AF_INET && strcmp(ifAddrStruct->ifa_name, "lo0") != 0) { // check it is IP4 and not lo0
}
ifAddrStruct = ifAddrStruct->ifa_next;
}
freeifaddrs(ifAddrStruct);
ifAddrStruct = NULL;
Comment