dracutdevs / dracut

dracut the event driven initramfs infrastructure
https://github.com/dracutdevs/dracut/wiki
GNU General Public License v2.0
573 stars 396 forks source link

fix(dracut-util): avoid memory leak #2608

Open aafeijoo-suse opened 5 months ago

aafeijoo-suse commented 5 months ago

The content of the kernel command line is assigned via strdup, but not freed on exit. This happens after each call to getarg(s), what makes an interesting amount of bytes not released at every boot.

master> grep -r -o -e getarg -e getargs modules.d | wc -l
457
master> export CMDLINE=$(< /proc/cmdline)
master> echo ${#CMDLINE}
130
afeijoo@localhost:~/src/dracut/opensuse-fork/master> valgrind --leak-check=full --show-leak-kinds=all ./dracut-getarg security
==24270== Memcheck, a memory error detector
==24270== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==24270== Using Valgrind-3.20.0 and LibVEX; rerun with -h for copyright info
==24270== Command: ./dracut-getarg security
==24270==
apparmor
==24270==
==24270== HEAP SUMMARY:
==24270==     in use at exit: 131 bytes in 1 blocks
==24270==   total heap usage: 2 allocs, 1 frees, 1,155 bytes allocated
==24270==
==24270== 131 bytes in 1 blocks are definitely lost in loss record 1 of 1
==24270==    at 0x4838744: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==24270==    by 0x490D839: strdup (in /lib64/libc-2.31.so)
==24270==    by 0x108AF6: getarg (util.c:188)
==24270==    by 0x108AF6: main (util.c:300)
==24270==
==24270== LEAK SUMMARY:
==24270==    definitely lost: 131 bytes in 1 blocks
==24270==    indirectly lost: 0 bytes in 0 blocks
==24270==      possibly lost: 0 bytes in 0 blocks
==24270==    still reachable: 0 bytes in 0 blocks
==24270==         suppressed: 0 bytes in 0 blocks
==24270==
==24270== For lists of detected and suppressed errors, rerun with: -s
==24270== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

Checklist

stale[bot] commented 3 months ago

This issue is being marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. If this is still an issue in the latest release of Dracut and you would like to keep it open please comment on this issue within the next 7 days. Thank you for your contributions.

stale[bot] commented 2 months ago

This issue is being marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. If this is still an issue in the latest release of Dracut and you would like to keep it open please comment on this issue within the next 7 days. Thank you for your contributions.