-
Notifications
You must be signed in to change notification settings - Fork 256
Fixed memory leak in UTMP processing #1329
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
Conversation
Fixes: f40bdfa (02-08-2023; "libmisc: implement `get_session_host()`") Signed-off-by: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
| #if defined(HAVE_STRUCT_UTMPX_UT_HOST) | ||
| if ((ut != NULL) && (ut->ut_host[0] != '\0')) { | ||
| *out = XSTRNDUP(ut->ut_host); | ||
| free (ut); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is being fixed already: a3667fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, noticed this too after making of this PR.
There is a second commit in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably it worth to merge the fix separately from the larger PR as it looks like independent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe; I'll think about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this patch set. It adds [[gnu::malloc(free)]], which I didn't, and that helps prevent this bug in the future. I'll merge it. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are welcome.
I'll update it based on your comments.
|
Related idea. The same approach is used in glibc. |
I prefer avoiding |
I personally prefer avoiding global variables (as the scope is not controlled), but a small static buffer inside the function is perfectly fine (the scope is fully controlled), it can make code better, faster, smaller, easier-to-read and safer at the same time. |
alejandro-colomar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
…tions Signed-off-by: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
ba8c330 to
822fe7f
Compare
|
Updated as requested. |
Obvious bug. Nothing to comment.