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

Commits on Jan 16, 2024

  1. fix(dracut-util): avoid memory leak

    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)
    ```
    aafeijoo-suse committed Jan 16, 2024
    Configuration menu
    Copy the full SHA
    217bcfd View commit details
    Browse the repository at this point in the history