BUG + patch: rdev applet doesn't free all memory

Peter van Vugt pwvanvugt at gmail.com
Mon Oct 27 20:52:27 UTC 2014


package: busybox
version: 1.23.0.git

The rdev applet fails to free the memory allocated by find_root_device().

~/busybox$ valgrind ./busybox rdev
==27379== Memcheck, a memory error detector
==27379== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==27379== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright
info
==27379== Command: ./busybox rdev
==27379==
/dev/dm-1 /
==27379==
==27379== HEAP SUMMARY:
==27379==     in use at exit: 10 bytes in 1 blocks
==27379==   total heap usage: 10 allocs, 9 frees, 295,354 bytes allocated
==27379==
==27379== LEAK SUMMARY:
==27379==    definitely lost: 10 bytes in 1 blocks
==27379==    indirectly lost: 0 bytes in 0 blocks
==27379==      possibly lost: 0 bytes in 0 blocks
==27379==    still reachable: 0 bytes in 0 blocks
==27379==         suppressed: 0 bytes in 0 blocks
==27379== Rerun with --leak-check=full to see details of leaked memory
==27379==
==27379== For counts of detected and suppressed errors, rerun with: -v
==27379== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Here is a simple patch that fixes the issue. Run rdev as above after
patching and Valgrind will report no leaks.

Peter


diff --git a/util-linux/rdev.c b/util-linux/rdev.c
index 4652817..b729d9d 100644
--- a/util-linux/rdev.c
+++ b/util-linux/rdev.c
@@ -23,10 +23,11 @@
 int rdev_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int rdev_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
 {
-       const char *root_device = find_block_device("/");
+       char *root_device = find_block_device("/");

        if (root_device) {
                printf("%s /\n", root_device);
+               free(root_device);
                return EXIT_SUCCESS;
        }
        return EXIT_FAILURE;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20141027/34a5ad91/attachment.html>


More information about the busybox mailing list