Skip to content

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 kai.vehmanen@linux.intel.com

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 <kai.vehmanen@linux.intel.com>
@kv2019i kv2019i force-pushed the 202212-soflogger-malloc-fail branch from c32b5f4 to 43cd115 Compare December 19, 2022 19:22
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


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