ROUTE(8): Free dynamic memory

This commit is contained in:
Sebastian Huber 2013-10-18 11:15:53 +02:00
parent 2a08d437fa
commit dfc416ef47

View File

@ -291,7 +291,7 @@ retry:
mib[5] = 0; /* no flags */
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
err(EX_OSERR, "route-sysctl-estimate");
if ((buf = malloc(needed)) == NULL)
if ((buf = malloc(needed)) == NULL && needed != 0)
errx(EX_OSERR, "malloc failed");
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
if (errno == ENOMEM && count++ < 10) {
@ -346,6 +346,7 @@ retry:
(void) printf("done\n");
}
}
free(buf);
}
const char *
@ -1193,7 +1194,7 @@ retry2:
mib[5] = 0; /* no flags */
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
err(EX_OSERR, "route-sysctl-estimate");
if ((buf = malloc(needed)) == NULL)
if ((buf = malloc(needed)) == NULL && needed != 0)
errx(EX_OSERR, "malloc failed");
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
if (errno == ENOMEM && count++ < 10) {
@ -1209,6 +1210,7 @@ retry2:
rtm = (struct rt_msghdr *)next;
print_rtmsg(c, rtm, rtm->rtm_msglen);
}
free(buf);
}
void