Fix: lttng-live: resource leak
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 14 Dec 2013 15:51:37 +0000 (10:51 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 14 Dec 2013 16:02:09 +0000 (11:02 -0500)
Found by Coverity:

** CID 1136987:  Resource leak  (RESOURCE_LEAK)
/formats/lttng-live/lttng-live-functions.c: 372 in lttng_live_attach_session()
/formats/lttng-live/lttng-live-functions.c: 386 in lttng_live_attach_session()
/formats/lttng-live/lttng-live-functions.c: 383 in lttng_live_attach_session()

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/lttng-live/lttng-live-functions.c

index 2d923618d2326fa707a32096aad1b80f26f2f744..b1bc28405f89ff006894ac84da393b97c26b5da7 100644 (file)
@@ -374,7 +374,17 @@ int lttng_live_attach_session(struct lttng_live_ctx *ctx, uint64_t id)
                        char *path;
 
                        path = strdup(LTTNG_METADATA_PATH_TEMPLATE);
-                       path = mkdtemp(path);
+                       if (!path) {
+                               perror("strdup");
+                               ret = -1;
+                               goto error;
+                       }
+                       if (!mkdtemp(path)) {
+                               perror("mkdtemp");
+                               free(path);
+                               ret = -1;
+                               goto error;
+                       }
                        ctx->session->streams[i].metadata_flag = 1;
                        snprintf(ctx->session->streams[i].path,
                                        sizeof(ctx->session->streams[i].path),
@@ -385,9 +395,11 @@ int lttng_live_attach_session(struct lttng_live_ctx *ctx, uint64_t id)
                                        S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
                        if (ret < 0) {
                                perror("open");
+                               free(path);
                                goto error;
                        }
                        ctx->session->streams[i].fd = ret;
+                       free(path);
                }
                ret = lttng_live_ctf_trace_assign(&ctx->session->streams[i],
                                be64toh(stream.ctf_trace_id));
This page took 0.026253 seconds and 4 git commands to generate.