From 769b7242bef6b88a60910f317b0fc738e9fdbe2b Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 26 Nov 2014 12:27:29 -0500 Subject: [PATCH] Fix: missing strdup oom check in lttng create.c MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Introduce tmp_path to ensure that no code path can possibly try to free the return value of utils_get_home_dir(). Re-using alloc_path for both static and dynamically allocated pointer is error-prone. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- src/bin/lttng/commands/create.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index e02b14142..0c318febb 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -324,16 +324,22 @@ static int create_session(void) */ url = NULL; } else if (!opt_no_output) { + char *tmp_path; + /* Auto output path */ - alloc_path = utils_get_home_dir(); - if (alloc_path == NULL) { + tmp_path = utils_get_home_dir(); + if (tmp_path == NULL) { ERR("HOME path not found.\n \ Please specify an output path using -o, --output PATH"); ret = CMD_FATAL; goto error; } - alloc_path = strdup(alloc_path); - + alloc_path = strdup(tmp_path); + if (!alloc_path) { + PERROR("allocating alloc_path"); + ret = CMD_FATAL; + goto error; + } ret = asprintf(&alloc_url, "file://%s/" DEFAULT_TRACE_DIR_NAME "/%s", alloc_path, session_name_date); -- 2.34.1