commit c4f133 libdwfl: find_debuginfo_in_patch don't alloca/strdupa
strings of unknown size. Introduced a memory leak in the case nothing
was found. Make sure before returning all temporary strings are all
freed.

Signed-off-by: Mark Wielaard <[email protected]>
---
 libdwfl/ChangeLog        |  5 +++++
 libdwfl/find-debuginfo.c | 18 ++++++++----------
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 956ac9f..a5253e2 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,5 +1,10 @@
 2015-06-06  Mark Wielaard  <[email protected]>
 
+       * find-debuginfo.c (find_debuginfo_in_path): Always free localpath,
+       localname and file_dirname.
+
+2015-06-06  Mark Wielaard  <[email protected]>
+
        * derelocate.c (cache_sections): Free sortrefs.
 
 2015-06-05  Mark Wielaard  <[email protected]>
diff --git a/libdwfl/find-debuginfo.c b/libdwfl/find-debuginfo.c
index 9b911c1..c523354 100644
--- a/libdwfl/find-debuginfo.c
+++ b/libdwfl/find-debuginfo.c
@@ -293,19 +293,13 @@ find_debuginfo_in_path (Dwfl_Module *mod, const char 
*file_name,
              }
            continue;
          default:
-           {
-           fail_free:
-             free (localpath);
-             free (localname);
-             free (file_dirname);
-             return -1;
-           }
+           goto fail_free;
          }
-      free (localpath);
-      free (localname);
-      free (file_dirname);
       if (validate (mod, fd, check, debuglink_crc))
        {
+         free (localpath);
+         free (localname);
+         free (file_dirname);
          *debuginfo_file_name = fname;
          return fd;
        }
@@ -315,6 +309,10 @@ find_debuginfo_in_path (Dwfl_Module *mod, const char 
*file_name,
 
   /* No dice.  */
   errno = 0;
+fail_free:
+  free (localpath);
+  free (localname);
+  free (file_dirname);
   return -1;
 }
 
-- 
2.1.0

Reply via email to