From 91689b95347bb232f14fac7a7ae3de85d9877e8f Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Sun, 19 Mar 2017 17:39:06 +0100 Subject: [PATCH 009/325] contrib/mtree: Fix small memory leak in spec() ... that was found when using makefs with an mtree spec: [fk@electrobsd /tmp/image-comparison] $valgrind --leak-check=full --tool=memcheck makefs -T 0 -B little -o label=blafasel -F mtree.spec image.part . ==35506== Memcheck, a memory error detector ==35506== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==35506== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info ==35506== Command: makefs -T 0 -B little -o label=blafasel -F mtree.spec image.part . ==35506== Calculated size of `image.part': 1917493248 bytes, 15 inodes Extent size set to 8192 density reduced from 127832884 to 907060 image.part: 1828.7MB (3745104 sectors) block size 8192, fragment size 1024 using 34 cylinder groups of 55.31MB, 7080 blks, 64 inodes. super-block backups (for fsck -b #) at: 32, 113312, 226592, 339872, 453152, 566432, 679712, 792992, 906272, 1019552, 1132832, 1246112, 1359392, 1472672, 1585952, 1699232, 1812512, 1925792, 2039072, 2152352, 2265632, 2378912, 2492192, 2605472, 2718752, 2832032, 2945312, 3058592, 3171872, 3285152, 3398432, 3511712, 3624992, 3738272, Populating `image.part' Image `image.part' complete ==35506== ==35506== HEAP SUMMARY: ==35506== in use at exit: 1,137,370 bytes in 271 blocks ==35506== total heap usage: 433,879 allocs, 433,608 frees, 1,792,473,254 bytes allocated ==35506== ==35506== 62 bytes in 1 blocks are definitely lost in loss record 1 of 15 ==35506== at 0x4C25DBE: realloc (in /usr/local/lib/valgrind/vgpreload_memcheck-amd64-freebsd.so) ==35506== by 0x41760A: spec (in /usr/sbin/makefs) ==35506== by 0x40BD90: apply_specfile (in /usr/sbin/makefs) ==35506== by 0x4090A7: main (in /usr/sbin/makefs) ==35506== ==35506== LEAK SUMMARY: ==35506== definitely lost: 62 bytes in 1 blocks ==35506== indirectly lost: 0 bytes in 0 blocks ==35506== possibly lost: 0 bytes in 0 blocks ==35506== still reachable: 1,137,308 bytes in 270 blocks ==35506== suppressed: 0 bytes in 0 blocks ==35506== Reachable blocks (those to which a pointer was found) are not shown. ==35506== To see them, rerun with: --leak-check=full --show-leak-kinds=all ==35506== ==35506== For counts of detected and suppressed errors, rerun with: -v ==35506== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) Obtained from: ElectroBSD --- contrib/mtree/spec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/mtree/spec.c b/contrib/mtree/spec.c index 6fbe6f534560..25ad285aec00 100644 --- a/contrib/mtree/spec.c +++ b/contrib/mtree/spec.c @@ -117,7 +117,7 @@ spec(FILE *fp) root = NULL; centry = last = NULL; - tname = NULL; + ntname = tname = NULL; tnamelen = 0; memset(&ginfo, 0, sizeof(ginfo)); for (mtree_lineno = 0; @@ -261,6 +261,7 @@ noparent: mtree_err("no parent node"); last = centry; } } + free(ntname); return (root); } -- 2.32.0