From 8aaf4fc46f5b0b1ed2b567734d06875a39047dd9 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Mon, 1 Jun 2015 17:07:26 +0200 Subject: [PATCH] libdwfl: Fix memory leak in __libdwfl_open_by_build_id. commit c57829 introduced a memory leak by passing the path string to strsep. strsep will change the given pointer and set it to NULL eventually. Causing the original pointer to leak. Fix by passing a copy of the pointer to strsep. Signed-off-by: Mark Wielaard --- libdwfl/ChangeLog | 5 +++++ libdwfl/dwfl_build_id_find_elf.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index f4e7484..4de3832 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,8 @@ +2015-06-01 Mark Wielaard + + * dwfl_build_id_find_elf.c (__libdwfl_open_by_build_id): Copy path + pointer before passing to strsep. + 2015-05-30 Mark Wielaard * link_map.c (check32): Use read_4ubyte_unaligned_noncvt to read diff --git a/libdwfl/dwfl_build_id_find_elf.c b/libdwfl/dwfl_build_id_find_elf.c index 215782a..99a5059 100644 --- a/libdwfl/dwfl_build_id_find_elf.c +++ b/libdwfl/dwfl_build_id_find_elf.c @@ -73,7 +73,8 @@ __libdwfl_open_by_build_id (Dwfl_Module *mod, bool debug, char **file_name, int fd = -1; char *dir; - while (fd < 0 && (dir = strsep (&path, ":")) != NULL) + char *paths = path; + while (fd < 0 && (dir = strsep (&paths, ":")) != NULL) { if (dir[0] == '+' || dir[0] == '-') ++dir; -- 2.7.4