Commit Diff


commit - 2a3c7d42fe7fd7fa34f4567b01a424ca9bdfa96b
commit + fd571e3ef4998485f4c5e94aa4615138c013dd49
blob - 5aeb90e8679e56a6f3a19776d01ddabc6142e524
blob + be52e6e809d65eca4d35118f2acb418ae32c1524
--- kroute.c
+++ kroute.c
@@ -100,6 +100,7 @@ struct rtdump *getrtdump(int af, int flags, int tablei
 	rtdump->buf = NULL;
 
 	while (1) {
+		char *p;
 		if (sysctl(mib, 7, NULL, &needed, NULL, 0) < 0) {
 			if (errno != ENOENT)
 				printf("%% getrtdump: unable to get estimate: %s\n",
@@ -108,11 +109,12 @@ struct rtdump *getrtdump(int af, int flags, int tablei
 		}
 		if (needed == 0)
 			break;
-		if ((rtdump->buf = realloc(rtdump->buf, needed)) == NULL) {
+		if ((p = realloc(rtdump->buf, needed)) == NULL) {
 			printf("%% getrtdump: realloc: %s\n", strerror(errno));
-			free(rtdump);
+			freertdump(rtdump);
 			return(NULL);
 		}
+		rtdump->buf = p;
 		if (sysctl(mib, 7, rtdump->buf, &needed, NULL, 0) < 0) {
 			if (errno == ENOMEM)
 				continue;