[Chilli] [PATCH] Fix: Memory leak on tun_discover()

Masashi Honma honma at ictec.co.jp
Tue Mar 2 12:21:46 UTC 2010


Hello.

The ic.ifc_buf field is allocated by calloc() but not freed. This
patch solves this issue and previous test program issue.

Index: tun.c
===================================================================
--- tun.c	(revision 294)
+++ tun.c	(working copy)
@@ -64,9 +64,16 @@
   }
 
   ic.ifc_buf = calloc((size_t)ic.ifc_len, 1);
+  if (ic.ifc_buf == NULL) {
+    log_err(errno, "calloc(ic.ifc_buf)");
+    close(fd);
+    return -1;
+  }
+
   if (ioctl(fd, SIOCGIFCONF, &ic) < 0) {
     log_err(errno, "ioctl(SIOCGIFCONF)");
     close(fd);
+    free(ic.ifc_buf);
     return -1;
   }
     
@@ -203,6 +210,7 @@
     }
   }
 
+  free(ic.ifc_buf);
   close(fd);
   return 0;
 }
Index: Makefile.am
===================================================================
--- Makefile.am	(revision 294)
+++ Makefile.am	(working copy)
@@ -3,7 +3,7 @@
 EXTRA_DIST = cmdline.ggo cmdline.patch
 
 lib_LTLIBRARIES = libchilli.la
-sbin_PROGRAMS = chilli chilli_response chilli_radconfig chilli_query chilli_opt queue
+sbin_PROGRAMS = chilli chilli_response chilli_radconfig chilli_query chilli_opt
 
 libchilli_la_SOURCES = \
 chilli.c tun.c tun.h ippool.c ippool.h radius.h radius.c \


Regards,
Masashi Honma.


More information about the Chilli mailing list