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

Masashi Honma honma at ictec.co.jp
Tue Mar 2 12:33:27 UTC 2010


(2010/03/02 21:21), Masashi Honma wrote:
> Hello.
>
> The ic.ifc_buf field is allocated by calloc() but not freed. This
> patch solves this issue and previous test program issue.

This is a patch torevision 295.

Index: tun.c
===================================================================
--- tun.c	(revision 295)
+++ 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;
  }

Regards,
Masashi Honma.


More information about the Chilli mailing list