]> err.no Git - util-linux/commitdiff
dmesg: fix memory leak in dmesg(1).
authorDavidlohr Bueso <dave@gnu.org>
Fri, 30 Jul 2010 15:43:36 +0000 (11:43 -0400)
committerKarel Zak <kzak@redhat.com>
Wed, 4 Aug 2010 09:46:38 +0000 (11:46 +0200)
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
sys-utils/dmesg.c

index fd184aaf49ad4b3bc2d3fcb789c77d63a147df2f..f1a7dcb7c380edd481acce5f2e7965d92231a2aa 100644 (file)
@@ -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;
 }