Skip to content
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

Merged
merged 1 commit into from
Dec 20, 2022

Conversation

kv2019i
Copy link
Collaborator

@kv2019i kv2019i commented Dec 19, 2022

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]

@@ -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");
Copy link
Collaborator

@paulstelian97 paulstelian97 Dec 19, 2022

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.

Copy link
Collaborator Author

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]>
@@ -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");
Copy link
Collaborator

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

@marc-hb marc-hb dismissed paulstelian97’s stale review December 19, 2022 23:11

Compilation issue fixed

@marc-hb
Copy link
Collaborator

marc-hb commented Dec 19, 2022

The ##################################################+| MAX failure in https://sof-ci.01.org/sofpr/PR6847/build3015/devicetest/index.html?model=ADLP_RVP_SDW_IPC4ZPH&testcase=check-pause-resume-capture-10 is obviously unrelated to this PR - but it's worrying.

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exit(EXIT_FAILURE);
abort();

I think this tends to print more information.

@marc-hb
Copy link
Collaborator

marc-hb commented Dec 19, 2022

Prefer abort() over exit(something), see demo in:

@kv2019i
Copy link
Collaborator Author

kv2019i commented Dec 20, 2022

The CI failure is unrelated (to a tools change). Proceeding with merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants