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>
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),
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));