-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(pkg/rootless): avoid memleak during init() contructor #25049
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(pkg/rootless): avoid memleak during init() contructor #25049
Conversation
Mmmh i am asked to add a new test, but well i am a bit unsure how to test this one :) |
661a6ce
to
114dfb3
Compare
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.
@giuseppe PTAL
The argv0
is never used anywhere AFAICT so can it not be dropped completely?
You mean from |
Yes I do not see why this is there at all but maybe there is something about c I am not understanding. Properly best to wait for @giuseppe to comment. |
pkg/rootless/rootless_linux.c
Outdated
{ | ||
can_shortcut = can_use_shortcut(argv); | ||
// It was freed by can_use_shortcut() call |
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.
can we drop the autocleanup from can_use_shortcut
so we don't have to deal with the special case here?
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.
Pushed the changes (i added the coauthor, hope it is fine)
sorry, I added a comment but forgot to send the review. Fixed now |
no prob, it happens all the time 😆 |
@@ -496,6 +494,8 @@ static void __attribute__((constructor)) init() | |||
fprintf(stderr, "cannot retrieve cmd line"); | |||
_exit (EXIT_FAILURE); | |||
} | |||
// Even if unused, this is needed to ensure we properly free the memory | |||
argv0 = argv[0]; |
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.
We always let init
be in charge of freeing argv0
now.
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.
LGTM
Thanks!
Can you please squash the commits? I don't think the previous commit need to be part of the history. |
`argv[0]`, ie: the full buffer allocated by `get_cmd_line_args`, was going to be freed only if `can_use_shortcut()` was called. Instead, let `init()` always manage `argv0` lifecycle. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
b3b3406
to
51fd6e9
Compare
Sure! Done |
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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: FedeDP, giuseppe, Luap99 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
argv[0]
, ie: the full buffer allocated byget_cmd_line_args
, was going to be freed only ifcan_use_shortcut()
was called. Since that is not always the case, add a fallback cleanup method.Spotted using
-fsanitize=address
:Fix was tested by running once again (after applying the patch) with asan.
Does this PR introduce a user-facing change?