From 91601d8c5d0dd1b6b9dfa80c6880d4bb59c25c09 Mon Sep 17 00:00:00 2001 From: "Stephen J. Kiernan" Date: Thu, 1 Jun 2017 16:44:39 +0000 Subject: [PATCH] When sysctlbyname fails, free buf before returning. Submitted by: Thomas Rix Reviewed by: jhb Approved by: sjg (mentor) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D9867 --- lib/libutil/kinfo_getvmobject.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/libutil/kinfo_getvmobject.c b/lib/libutil/kinfo_getvmobject.c index 7e031dadccb0..de55650a518b 100644 --- a/lib/libutil/kinfo_getvmobject.c +++ b/lib/libutil/kinfo_getvmobject.c @@ -46,8 +46,10 @@ kinfo_getvmobject(int *cntp) buf = NULL; for (i = 0; i < 3; i++) { - if (sysctlbyname("vm.objects", NULL, &len, NULL, 0) < 0) + if (sysctlbyname("vm.objects", NULL, &len, NULL, 0) < 0) { + free(buf); return (NULL); + } buf = reallocf(buf, len); if (buf == NULL) return (NULL);