summaryrefslogtreecommitdiffstats
path: root/freebsd/sbin/ifconfig/ifclone.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2013-10-22 10:03:10 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2013-10-31 13:18:49 +0100
commitb833cc4c4a6e703b851200da046c057bb5cd4a1d (patch)
treee64e41e77ac454a6f3ad26b8e88895964cb1eddb /freebsd/sbin/ifconfig/ifclone.c
parentIFCONFIG(8): Initialize global variables in ctors (diff)
downloadrtems-libbsd-b833cc4c4a6e703b851200da046c057bb5cd4a1d.tar.bz2
IFCONFIG(8): Fix some resource leaks
Diffstat (limited to 'freebsd/sbin/ifconfig/ifclone.c')
-rw-r--r--freebsd/sbin/ifconfig/ifclone.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/freebsd/sbin/ifconfig/ifclone.c b/freebsd/sbin/ifconfig/ifclone.c
index 84ec61bd..2de84c34 100644
--- a/freebsd/sbin/ifconfig/ifclone.c
+++ b/freebsd/sbin/ifconfig/ifclone.c
@@ -70,8 +70,10 @@ list_cloners(void)
ifcr.ifcr_count = ifcr.ifcr_total;
ifcr.ifcr_buffer = buf;
- if (ioctl(s, SIOCIFGCLONERS, &ifcr) < 0)
+ if (ioctl(s, SIOCIFGCLONERS, &ifcr) < 0) {
+ free(buf);
err(1, "SIOCIFGCLONERS for names");
+ }
/*
* In case some disappeared in the mean time, clamp it down.
@@ -104,6 +106,11 @@ clone_setdefcallback(const char *ifprefix, clone_callback_func *p)
struct clone_defcb *dcp;
dcp = malloc(sizeof(*dcp));
+#ifndef __rtems__
+ if (dcp == NULL) {
+ errx(1, "unable to allocate clone");
+ }
+#endif /* __rtems__ */
strlcpy(dcp->ifprefix, ifprefix, IFNAMSIZ-1);
dcp->clone_cb = p;
SLIST_INSERT_HEAD(&clone_defcbh, dcp, next);
@@ -199,3 +206,15 @@ clone_ctor(void)
opt_register(&clone_Copt);
#undef N
}
+#ifdef __rtems__
+void
+clone_dtor(void)
+{
+ struct clone_defcb *dcp;
+ struct clone_defcb *dcp_tmp;
+
+ SLIST_FOREACH_SAFE(dcp, &clone_defcbh, next, dcp_tmp) {
+ free(dcp);
+ }
+}
+#endif /* __rtems__ */