-
Notifications
You must be signed in to change notification settings - Fork 41
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
libkmod and depmod: Release memory on error paths #228
Conversation
Sorry, we've got cconflicts and this now needs a rebase. |
37b1738
to
a65f257
Compare
Rebased. |
Codecov ReportAttention: Patch coverage is
|
@stoeckmann can we drop the The last commit uses it although we can live with an 2 extra lines of code. |
6d205c9
to
4355524
Compare
Add a macro to reduce amount of explicit while-loops for removal of nodes and release of their associated data in code base. Signed-off-by: Tobias Stoeckmann <[email protected]>
If a list node could not be added, release already allocated data which was supposed to end up in list. Signed-off-by: Tobias Stoeckmann <[email protected]>
Check malloc return value and clean up resources if allocation fails. Signed-off-by: Tobias Stoeckmann <[email protected]>
Do not override pointers to first list nodes if appending failed, otherwise it's impossible to release already existing nodes of these lists afterwards. Remove the now unused function kmod_list_remove_n_latest as well. Signed-off-by: Tobias Stoeckmann <[email protected]>
4355524
to
913a166
Compare
Add a macro to reduce amount of explicit while-loops for removal of nodes and release of their associated data in code base. Signed-off-by: Tobias Stoeckmann <[email protected]> Link: #228 Signed-off-by: Lucas De Marchi <[email protected]>
If a list node could not be added, release already allocated data which was supposed to end up in list. Signed-off-by: Tobias Stoeckmann <[email protected]> Link: #228 Signed-off-by: Lucas De Marchi <[email protected]>
Check malloc return value and clean up resources if allocation fails. Signed-off-by: Tobias Stoeckmann <[email protected]> Link: #228 Signed-off-by: Lucas De Marchi <[email protected]>
Do not override pointers to first list nodes if appending failed, otherwise it's impossible to release already existing nodes of these lists afterwards. Remove the now unused function kmod_list_remove_n_latest as well. Signed-off-by: Tobias Stoeckmann <[email protected]> Link: #228 Signed-off-by: Lucas De Marchi <[email protected]>
Applied, thanks |
The libkmod library as well as depmod leaked memory on error paths related to kmod_lists:
kmod_list_append
failure (out of memory), the soon to belist->data
was not freedTo make it a lot easier to review, I have added
kmod_list_release
which is a macro and abstracts the explicit while-loops from the code. I use it for case 2 to handle error cases more smoothly. This in turn made functionkmod_list_remove_n_latest
obsolete, so I removed it.Proof of Concept (for case 2):
Either compile kmod with address sanitizer (for leak detection) or use valgrind for modprobe call later on
Create a modules config with an alias resolving to two modules (first one can be created in memory, second one is too long)
The option
-a
is important to not trigger a FATAL log, which would abort the modprobe call without trying to release all resources. Since the leak occurs in library code, it should be fixed so allocated memory can be freed when requested.