From: David Goulet Date: Wed, 12 Mar 2014 17:55:44 +0000 (-0400) Subject: Fix: possible unlink on uninitialized buffer path X-Git-Tag: v2.5.0-rc1~115 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=db47121890a96d48c3ad09d83fca41cecd06e555 Fix: possible unlink on uninitialized buffer path Fixes coverity issue 1191752. Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index d2bf09208..22fab9c05 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -1398,6 +1398,7 @@ int save_session(struct ltt_session *session, struct lttng_save_session_attr *attr, lttng_sock_cred *creds) { int ret, fd; + unsigned int file_opened = 0; /* Indicate if the file has been opened */ char config_file_path[PATH_MAX]; size_t len; struct config_writer *writer = NULL; @@ -1485,6 +1486,7 @@ int save_session(struct ltt_session *session, ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; } + file_opened = 1; writer = config_writer_create(fd); if (!writer) { @@ -1579,7 +1581,7 @@ end: } if (ret) { /* Delete file in case of error */ - if (unlink(config_file_path)) { + if (file_opened && unlink(config_file_path)) { PERROR("Unlinking XML session configuration."); } }