From: Michael Jeanson Date: Thu, 29 Nov 2018 21:49:51 +0000 (-0500) Subject: Fix: warning 'fd' may be used uninitialized X-Git-Tag: v2.10.6~10 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2fc93c34017b03b792f48f913e117a833ef4a34f;p=lttng-tools.git Fix: warning 'fd' may be used uninitialized Initialize fd to invalid '-1' and remove unnecessary file_opened. Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index 834b8739e..c51338e17 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -1890,8 +1890,7 @@ static 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 */ + int ret, fd = -1; char config_file_path[PATH_MAX]; size_t len; struct config_writer *writer = NULL; @@ -1984,7 +1983,6 @@ int save_session(struct ltt_session *session, ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; } - file_opened = 1; writer = config_writer_create(fd, 1); if (!writer) { @@ -2089,12 +2087,12 @@ end: } if (ret) { /* Delete file in case of error */ - if (file_opened && unlink(config_file_path)) { + if ((fd >= 0) && unlink(config_file_path)) { PERROR("Unlinking XML session configuration."); } } - if (file_opened) { + if (fd >= 0) { ret = close(fd); if (ret) { PERROR("Closing XML session configuration");