]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsmem: fix memory leak [coverity scan]
authorKarel Zak <kzak@redhat.com>
Tue, 20 Feb 2018 14:04:51 +0000 (15:04 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 20 Feb 2018 14:04:51 +0000 (15:04 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lsmem.c

index 19a727465605fb10177e5f2466315ebea2f09abe..3e06e43be74ee7a3ff596bfa0fbd09af05dcbf92 100644 (file)
@@ -323,12 +323,19 @@ static void print_summary(struct lsmem *lsmem)
                printf("%-23s %15"PRId64"\n",_("Total online memory:"), lsmem->mem_online);
                printf("%-23s %15"PRId64"\n",_("Total offline memory:"), lsmem->mem_offline);
        } else {
-               printf("%-23s %5s\n",_("Memory block size:"),
-                       size_to_human_string(SIZE_SUFFIX_1LETTER, lsmem->block_size));
-               printf("%-23s %5s\n",_("Total online memory:"),
-                       size_to_human_string(SIZE_SUFFIX_1LETTER, lsmem->mem_online));
-               printf("%-23s %5s\n",_("Total offline memory:"),
-                       size_to_human_string(SIZE_SUFFIX_1LETTER, lsmem->mem_offline));
+               char *p;
+
+               if ((p = size_to_human_string(SIZE_SUFFIX_1LETTER, lsmem->block_size)))
+                       printf("%-23s %5s\n",_("Memory block size:"), p);
+               free(p);
+
+               if ((p = size_to_human_string(SIZE_SUFFIX_1LETTER, lsmem->mem_online)))
+                       printf("%-23s %5s\n",_("Total online memory:"), p);
+               free(p);
+
+               if ((p = size_to_human_string(SIZE_SUFFIX_1LETTER, lsmem->mem_offline)))
+                       printf("%-23s %5s\n",_("Total offline memory:"), p);
+               free(p);
        }
 }