From 4d64893b868297e259f578267a18e18275e538c1 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Mon, 19 Dec 2022 17:15:36 +0200 Subject: [PATCH] sof-logger: exit with error if malloc fails 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 --- tools/logger/logger.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/logger/logger.c b/tools/logger/logger.c index b5df7e185..11e375363 100644 --- a/tools/logger/logger.c +++ b/tools/logger/logger.c @@ -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);