Skip to content

Commit

Permalink
sof-logger: exit with error if malloc fails
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
kv2019i committed Dec 19, 2022
1 parent 764ce67 commit 43cd115
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tools/logger/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

strcpy(fpath, watched_dir);
strcat(fpath, "/");
strcat(fpath, expected_file);
Expand Down

0 comments on commit 43cd115

Please sign in to comment.