From 5abb148f43920aa9b47fb98ca84bb182972b48d0 Mon Sep 17 00:00:00 2001 From: Xin LI Date: Sat, 12 Jan 2008 00:11:26 +0000 Subject: [PATCH] - Handle the case where interface from "middle" is missing by more carefully inspecting the return value from sysctl(3). [1] - Use calloc instead of malloc+memset of zero. Submitted by: Alexander Chernikov [1] PR: bin/119581 MFC after: 2 weeks --- usr.bin/systat/ifstat.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/usr.bin/systat/ifstat.c b/usr.bin/systat/ifstat.c index 27bf9ecfe676..62773e9fd09c 100644 --- a/usr.bin/systat/ifstat.c +++ b/usr.bin/systat/ifstat.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "systat.h" #include "extern.h" @@ -210,10 +211,9 @@ initifstat(void) SLIST_INIT(&curlist); for (i = 0; i < n; i++) { - p = (struct if_stat *)malloc(sizeof(struct if_stat)); + p = (struct if_stat *)calloc(1, sizeof(struct if_stat)); if (p == NULL) IFSTAT_ERR(1, "out of memory"); - memset((void *)p, 0, sizeof(struct if_stat)); SLIST_INSERT_HEAD(&curlist, p, link); p->if_row = i+1; getifmibdata(p->if_row, &p->if_mib); @@ -384,8 +384,8 @@ getifmibdata(int row, struct ifmibdata *data) datalen = sizeof(*data); name[4] = row; - if (sysctl(name, 6, (void *)data, (size_t *)&datalen, (void *)NULL, - (size_t)0) != 0) + if ((sysctl(name, 6, (void *)data, (size_t *)&datalen, (void *)NULL, + (size_t)0) != 0) && (errno != ENOENT)) IFSTAT_ERR(2, "sysctl error getting interface data"); }