From 219da9223d14aa21e4feb4fe850eb4c1691c98d8 Mon Sep 17 00:00:00 2001 From: Davidlohr Bueso Date: Fri, 30 Jul 2010 11:43:36 -0400 Subject: [PATCH] dmesg: fix memory leak in dmesg(1). Signed-off-by: Davidlohr Bueso --- sys-utils/dmesg.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index fd184aaf..f1a7dcb7 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -111,12 +111,12 @@ main(int argc, char *argv[]) { if (bufsize) { sz = bufsize + 8; - buf = (char *) malloc(sz); + buf = (char *) malloc(sz * sizeof(char)); n = klogctl(cmd, buf, sz); } else { sz = 16392; while (1) { - buf = (char *) malloc(sz); + buf = (char *) malloc(sz * sizeof(char)); n = klogctl(3, buf, sz); /* read only */ if (n != sz || sz > (1<<28)) break; @@ -147,5 +147,6 @@ main(int argc, char *argv[]) { } if (lastc != '\n') putchar('\n'); + free(buf); return 0; } -- 2.39.5