]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdwfl: Fix build_id memory leak in dwfl_segment_report_module.
authorMark Wielaard <mjw@redhat.com>
Mon, 23 Dec 2013 22:21:59 +0000 (23:21 +0100)
committerMark Wielaard <mjw@redhat.com>
Tue, 31 Dec 2013 12:58:32 +0000 (13:58 +0100)
We might already have allocated memory to hold the build_id early in
consider_notes when we called consider_phdr for the program headers
we've read from the image. We would leak that memory when we don't use
it then because we return early/fail. This can be because either we
didn't find the correct bias or we skip the module because it would
conflict in address space with any already existing module of DWFL.
In both cases explicitly free the build_id memory.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libdwfl/ChangeLog
libdwfl/dwfl_segment_report_module.c

index 8e50f2f2e2f044d6505ca3e496972a24214fe398..807fc2b1e01d612edb02b0fac9e2bee423cdd821 100644 (file)
@@ -1,3 +1,8 @@
+2013-12-23  Mark Wielaard  <mjw@redhat.com>
+
+       * dwfl_segment_report_module.c (dwfl_segment_report_module): Free
+       build_id before returning early.
+
 2013-12-23  Mark Wielaard  <mjw@redhat.com>
 
        * linux-pid-attach.c (__libdwfl_attach_state_for_pid): Report actual
index 55f6d38838b35c0dc5fdf4899d005d9fec490de9..fd967e9a3796785d9229942542bccc8deea18baf 100644 (file)
@@ -427,7 +427,10 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
   /* We must have seen the segment covering offset 0, or else the ELF
      header we read at START was not produced by these program headers.  */
   if (unlikely (!found_bias))
-    return finish ();
+    {
+      free (build_id);
+      return finish ();
+    }
 
   /* Now we know enough to report a module for sure: its bounds.  */
   module_start += bias;
@@ -519,7 +522,10 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
              }
          }
       if (skip_this_module)
-       return finish ();
+       {
+         free (build_id);
+         return finish ();
+       }
     }
 
   /* Our return value now says to skip the segments contained