microcom.c: Call cleanup routines only once#56
Open
jonrebm wants to merge 1 commit into
Open
Conversation
Merged
Contributor
Author
jonrebm
force-pushed
the
cleaup-routines
branch
from
January 15, 2026 17:17
b07e1fe to
3efc952
Compare
Contributor
Author
|
Thank you @michaelolbrich. Seems I need to run another round of testing. |
Contributor
Author
|
Applied feedback from @michaelolbrich, made microcom_exit static, rebased to main |
Repeated call to ios->exit(ios); was observed as used after free using asan. Only call it once: In the exit handler. Always call the exit handler, either via sigaction or via atexit, and check there whether listenonly is set and there skip resetting the terminal if so. Do not reset the terminal elsewhere. Do not call the exit handler from the quit command, just call exit, and rely on atexit. Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
| write(1, "exiting\n", 8); | ||
| static const char exit_msg[] = "exiting\n"; | ||
|
|
||
| if (write(STDOUT_FILENO, exit_msg, sizeof(exit_msg) - 1) < 0) { |
Member
There was a problem hiding this comment.
Is this to avoid a warning about ignoring the return value? or why is this here?
(void)write(...); is the typical way to handle that, I think.
Contributor
Author
There was a problem hiding this comment.
Yes, for compiler and reader to see that error checking is omitted purposely. I thought that it looked better this way but I'll change it given you find that more idiomatic.
| ret = ios->set_speed(ios, current_speed); | ||
| if (ret) | ||
| goto cleanup_ios; | ||
| exit(1); |
Member
There was a problem hiding this comment.
This is before atexit() is configured. Don't you need to call at least ios->exit(ios); here?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Repeated call to ios->exit(ios); was observed as used after free using asan. Only call it once: In the exit handler.
Always call the exit handler and check there whether listenonly is set and there skip resetting the terminal if so.
Do not reset the terminal elsewhere.
Do not call the exit handler from the quit command, call exit instead.