Skip to content

Commit

Permalink
Fix: lttng: free sessions in cmd_destroy
Browse files Browse the repository at this point in the history
When doing `lttng destroy`, I get:

    Direct leak of 4385 byte(s) in 1 object(s) allocated from:
        #0 0x7f74ae025459 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
        #1 0x7f74add4129a in zmalloc /home/simark/src/lttng-tools/src/common/macros.h:45
        #2 0x7f74add42b9d in recv_sessiond_optional_data /home/simark/src/lttng-tools/src/lib/lttng-ctl/lttng-ctl.c:494
        #3 0x7f74add42f9a in lttng_ctl_ask_sessiond_fds_varlen /home/simark/src/lttng-tools/src/lib/lttng-ctl/lttng-ctl.c:596
        #4 0x7f74add41714 in lttng_ctl_ask_sessiond_varlen_no_cmd_header /home/simark/src/lttng-tools/src/lib/lttng-ctl/lttng-ctl-helper.h:58
        #5 0x7f74add41747 in lttng_ctl_ask_sessiond /home/simark/src/lttng-tools/src/lib/lttng-ctl/lttng-ctl-helper.h:78
        #6 0x7f74add4a922 in lttng_list_sessions /home/simark/src/lttng-tools/src/lib/lttng-ctl/lttng-ctl.c:2105
        #7 0x56472bcbdf80 in cmd_destroy /home/simark/src/lttng-tools/src/bin/lttng/commands/destroy.c:330
        #8 0x56472bd00764 in handle_command /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:237
        #9 0x56472bd01218 in parse_args /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:426
        #10 0x56472bd0151a in main /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:475
        #11 0x7f74ad963b24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)

This is due to cmd_destroy not free'ing the result of
lttng_list_sessions. Fix that.

Change-Id: Iff2e75e6ec1cdcd0bdfdbbc3d5099422e592905b
Signed-off-by: Simon Marchi <[email protected]>
Signed-off-by: Jérémie Galarneau <[email protected]>
  • Loading branch information
simark authored and jgalar committed Aug 2, 2021
1 parent 092545c commit 6a8d2ab
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/bin/lttng/commands/destroy.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ int cmd_destroy(int argc, const char **argv)
char *session_name = NULL;
const char *leftover = NULL;

struct lttng_session *sessions;
struct lttng_session *sessions = NULL;
int count;
int found;

Expand Down Expand Up @@ -423,6 +423,8 @@ int cmd_destroy(int argc, const char **argv)
free(session_name);
}

free(sessions);

/* Overwrite ret if an error occurred during destroy_session/all */
ret = command_ret ? command_ret : ret;

Expand Down

0 comments on commit 6a8d2ab

Please sign in to comment.