Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aafeijoo-suse
Copy link
Member

@aafeijoo-suse aafeijoo-suse commented Jan 16, 2024

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

  • I have tested it locally
  • I have reviewed and updated any documentation if relevant
  • I am providing new code and test(s) for it

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)
```
src/util/util.c Dismissed Show dismissed Hide dismissed
@aafeijoo-suse aafeijoo-suse marked this pull request as ready for review January 16, 2024 15:03
Copy link

stale bot commented Mar 13, 2024

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 stale bot added the stale communication is stuck label Mar 13, 2024
@aafeijoo-suse aafeijoo-suse removed the stale communication is stuck label Mar 14, 2024
Copy link

stale bot commented Apr 22, 2024

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 stale bot added the stale communication is stuck label Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dracut-util stale communication is stuck
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant