From: Yu Watanabe Date: Fri, 11 Jul 2025 11:16:02 +0000 (+0900) Subject: udevadm: fix memleak X-Git-Tag: v258-rc1~85 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a58d8ed51a4b1f7e8febb52dc9f0b60cd916600;p=thirdparty%2Fsystemd.git udevadm: fix memleak Fixes a bug in a4a6e216739506153df88cbc8ac078cba4591e5f. Fixes the following memleak: ``` $ sudo valgrind --leak-check=full build/udevadm cat /usr/lib/udev/rules.d ==3975939== ==3975939== HEAP SUMMARY: ==3975939== in use at exit: 640 bytes in 1 blocks ==3975939== total heap usage: 7,657 allocs, 7,656 frees, 964,328 bytes allocated ==3975939== ==3975939== 640 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==3975939== at 0x4841866: malloc (vg_replace_malloc.c:446) ==3975939== by 0x4ACA71F: malloc_multiply (alloc-util.h:92) ==3975939== by 0x4ACF988: _hashmap_dump_entries_sorted (hashmap.c:2167) ==3975939== by 0x4ACFC76: _hashmap_dump_sorted (hashmap.c:2209) ==3975939== by 0x4AA60A4: hashmap_dump_sorted (hashmap.h:311) ==3975939== by 0x4AA9077: dump_files (conf-files.c:397) ==3975939== by 0x4AAA14E: conf_files_list_strv_full (conf-files.c:596) ==3975939== by 0x42426A: search_rules_file (udevadm-util.c:301) ==3975939== by 0x424768: search_rules_files (udevadm-util.c:334) ==3975939== by 0x41287D: cat_main (udevadm-cat.c:110) ==3975939== by 0x4A7B911: dispatch_verb (verbs.c:139) ==3975939== by 0x427272: udevadm_main (udevadm.c:121) ==3975939== ==3975939== LEAK SUMMARY: ==3975939== definitely lost: 640 bytes in 1 blocks ==3975939== indirectly lost: 0 bytes in 0 blocks ==3975939== possibly lost: 0 bytes in 0 blocks ==3975939== still reachable: 0 bytes in 0 blocks ==3975939== suppressed: 0 bytes in 0 blocks ==3975939== ==3975939== For lists of detected and suppressed errors, rerun with: -s ==3975939== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) ``` --- diff --git a/src/udev/udevadm-util.c b/src/udev/udevadm-util.c index 09c0be1565e..5c6663b16e1 100644 --- a/src/udev/udevadm-util.c +++ b/src/udev/udevadm-util.c @@ -305,7 +305,7 @@ static int search_rules_file(const char *s, const char *root, ConfFile ***files, if (!GREEDY_REALLOC_APPEND(*files, *n_files, f, n)) return log_oom(); - TAKE_PTR(f); + f = mfree(f); /* The array elements are owned by 'files'. So, conf_file_free_many() must not be called. */ n = 0; return 0; }