Skip to contentSkip to conversation

Fix: warning 'fd' may be used uninitialized

PATCH Jérémie Galarneau 1 participant 1 message Jan 22, 2019 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Merged in master, stable-2.11, stable-2.10, and stable-2.9.

Thanks!
Jérémie

Quoted 48 lines · Michael Jeanson

Initialize fd to invalid '-1' and remove unnecessary file_opened.

---
 src/bin/lttng-sessiond/save.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
src/bin/lttng-sessiond/save.c +3 -6
index 8daf870c..6ce992b2 100644
@@ -2284,8 +2284,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;
@@ -2378,7 +2377,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) {
@@ -2492,12 +2490,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");
--

2.17.1

Signature · 7 lines
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev