[rtems-libbsd commit] netstat: Fix invalid free()

Sebastian Huber sebh at rtems.org
Thu Sep 18 10:55:11 UTC 2014


Module:    rtems-libbsd
Branch:    master
Commit:    705d1bf8d2d9db0a4ded8b37526e34542eec813c
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=705d1bf8d2d9db0a4ded8b37526e34542eec813c

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Sep 18 13:01:25 2014 +0200

netstat: Fix invalid free()

---

 freebsd/usr.bin/netstat/bpf.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/freebsd/usr.bin/netstat/bpf.c b/freebsd/usr.bin/netstat/bpf.c
index 50e12fa..824319c 100644
--- a/freebsd/usr.bin/netstat/bpf.c
+++ b/freebsd/usr.bin/netstat/bpf.c
@@ -55,12 +55,10 @@ __FBSDID("$FreeBSD$");
 
 /* print bpf stats */
 
+#ifndef __rtems__
 static char *
 bpf_pidname(pid_t pid)
 {
-#ifdef __rtems__
-	return "rtems";
-#else /* __rtems__ */
 	struct kinfo_proc newkp;
 	int error, mib[4];
 	size_t size;
@@ -76,8 +74,8 @@ bpf_pidname(pid_t pid)
 		return (strdup("??????"));
 	}
 	return (strdup(newkp.ki_comm));
-#endif /* __rtems__ */
 }
+#endif /* __rtems__ */
 
 static void
 bpf_flags(struct xbpf_d *bd, char *flagbuf)
@@ -139,12 +137,18 @@ bpf_stats(char *ifname)
 		if (ifname && strcmp(ifname, d->bd_ifname) != 0)
 			continue;
 		bpf_flags(d, flagbuf);
+#ifndef __rtems__
 		pname = bpf_pidname(d->bd_pid);
+#else /* __rtems__ */
+		pname = "??????";
+#endif /* __rtems__ */
 		(void) printf("%5d %6s %7s %9ju %9ju %9ju %5d %5d %s\n",
 		    d->bd_pid, d->bd_ifname, flagbuf,
 		    d->bd_rcount, d->bd_dcount, d->bd_fcount,
 		    d->bd_slen, d->bd_hlen, pname);
+#ifndef __rtems__
 		free(pname);
+#endif /* __rtems__ */
 	}
 	free(bd);
 }



More information about the vc mailing list