Fix: possible unlink on uninitialized buffer path
authorDavid Goulet <dgoulet@efficios.com>
Wed, 12 Mar 2014 17:55:44 +0000 (13:55 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 12 Mar 2014 17:55:44 +0000 (13:55 -0400)
Fixes coverity issue 1191752.

Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-sessiond/save.c

index d2bf09208e05b3c4a472657d31ea366b4c22ddba..22fab9c05bd013020a83c368fc6a0cadf7ad09e3 100644 (file)
@@ -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.");
                }
        }
This page took 0.027586 seconds and 5 git commands to generate.