From: Sami Kerola Date: Tue, 11 Nov 2014 21:34:30 +0000 (+0000) Subject: mkswap: remove memory leaks [LeakSanitizer] [valgrind] X-Git-Tag: v2.26-rc1~207 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=acec6eec4e29f5951bee5b5db9534566abec27bb;p=thirdparty%2Futil-linux.git mkswap: remove memory leaks [LeakSanitizer] [valgrind] ==18922==ERROR: LeakSanitizer: detected memory leaks Direct leak of 8 byte(s) in 1 object(s) allocated from: #0 0x49d12b in __interceptor_malloc (/home/src/util-linux/.libs/lt-mkswap+0x49d12b) #1 0x7faf2a5069c9 in __GI___strdup (/usr/lib/libc.so.6+0x819c9) #2 0xffff96e7e33 () SUMMARY: AddressSanitizer: 8 byte(s) leaked in 1 allocation(s). And another one that valgrind found. ==6316== 8 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==6316== at 0x4C29F90: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==6316== by 0x5E3F9C9: strdup (in /usr/lib/libc-2.20.so) ==6316== by 0x43A25F: size_to_human_string (strutils.c:495) ==6316== by 0x42B35C: main (mkswap.c:488) Signed-off-by: Sami Kerola --- diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index c4fe8c92b9..d34e2fd351 100644 --- a/disk-utils/mkswap.c +++ b/disk-utils/mkswap.c @@ -323,6 +323,7 @@ static void wipe_device(struct mkswap_control *ctl) fprintf(stderr, _(" (compiled without libblkid). ")); fprintf(stderr, _("Use -f to force.\n")); } + free(type); #ifdef HAVE_LIBBLKID blkid_free_probe(pr); #endif @@ -488,6 +489,7 @@ int main(int argc, char **argv) printf(_("Setting up swapspace version %d, size = %s (%ju bytes)\n"), version, strsz, sz); + free(strsz); set_signature(&ctl); set_uuid_and_label(&ctl);