From 83215d66bbc361b174835895a3f6166e7c2fcd86 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 4 Sep 2015 02:00:09 -0400 Subject: [PATCH] Fix: elf: leaks on error paths Signed-off-by: Mathieu Desnoyers --- liblttng-ust-dl/lttng-ust-dl.c | 6 ++++-- liblttng-ust/lttng-ust-elf.c | 7 +++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/liblttng-ust-dl/lttng-ust-dl.c b/liblttng-ust-dl/lttng-ust-dl.c index d6b80714..d6abeff0 100644 --- a/liblttng-ust-dl/lttng-ust-dl.c +++ b/liblttng-ust-dl/lttng-ust-dl.c @@ -70,9 +70,9 @@ void lttng_ust_dl_dlopen(void *so_base, const char *so_name, void *ip) char resolved_path[PATH_MAX]; struct lttng_ust_elf *elf; uint64_t memsz; - uint8_t *build_id; + uint8_t *build_id = NULL; size_t build_id_len; - char *dbg_file; + char *dbg_file = NULL; uint32_t crc; int has_build_id = 0, has_debug_link = 0; int ret; @@ -119,6 +119,8 @@ void lttng_ust_dl_dlopen(void *so_base, const char *so_name, void *ip) } end: + free(dbg_file); + free(build_id); lttng_ust_elf_destroy(elf); return; } diff --git a/liblttng-ust/lttng-ust-elf.c b/liblttng-ust/lttng-ust-elf.c index 026d65ce..ce58539e 100644 --- a/liblttng-ust/lttng-ust-elf.c +++ b/liblttng-ust/lttng-ust-elf.c @@ -478,6 +478,7 @@ int lttng_ust_elf_get_build_id_from_segment( *found = _found; return 0; error: + free(_build_id); return -1; } @@ -624,10 +625,8 @@ end: return 0; error: - if (section_name) { - free(section_name); - } - + free(_filename); + free(section_name); return -1; } -- 2.34.1