From: Davidlohr Bueso Date: Fri, 30 Jul 2010 15:43:36 +0000 (-0400) Subject: dmesg: fix memory leak in dmesg(1). X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=219da9223d14aa21e4feb4fe850eb4c1691c98d8;p=util-linux dmesg: fix memory leak in dmesg(1). Signed-off-by: Davidlohr Bueso --- 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; }