-
Notifications
You must be signed in to change notification settings - Fork 314
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
sof-logger: exit with error if malloc fails #6847
sof-logger: exit with error if malloc fails #6847
Conversation
tools/logger/logger.c
Outdated
@@ -223,6 +223,11 @@ static void *wait_open(const char *watched_dir, const char *expected_file) | |||
|
|||
char * const fpath = malloc(strlen(watched_dir) + 1 + strlen(expected_file) + 1); | |||
|
|||
if (!fpath) { | |||
fprintf(stdderr, "error: can't allocate memory\n"); |
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.
Typo: stderr. Approve when this is fixed.
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.
Oops indeed, V2 uploaded. I had compile tested locally, or so I thought. Now went and retested all the four sof-logger PRs I pushed today.
In user-space tools, memory allocations can reasonably be expected to always succeed. Make this assumption explicit by adding error handling after malloc. Signed-off-by: Kai Vehmanen <[email protected]>
c32b5f4
to
43cd115
Compare
@@ -223,6 +223,11 @@ static void *wait_open(const char *watched_dir, const char *expected_file) | |||
|
|||
char * const fpath = malloc(strlen(watched_dir) + 1 + strlen(expected_file) + 1); | |||
|
|||
if (!fpath) { | |||
fprintf(stderr, "error: can't allocate memory\n"); |
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.
A more specific error message would not hurt but it's never going to get printed anyway so who cares
The See also |
@@ -223,6 +223,11 @@ static void *wait_open(const char *watched_dir, const char *expected_file) | |||
|
|||
char * const fpath = malloc(strlen(watched_dir) + 1 + strlen(expected_file) + 1); | |||
|
|||
if (!fpath) { | |||
fprintf(stderr, "error: can't allocate memory\n"); | |||
exit(EXIT_FAILURE); |
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.
exit(EXIT_FAILURE); | |
abort(); |
I think this tends to print more information.
Prefer |
The CI failure is unrelated (to a tools change). Proceeding with merge. |
In user-space tools, memory allocations can reasonably be expected to always succeed. Make this assumption explicit by adding error handling after malloc.
Signed-off-by: Kai Vehmanen [email protected]