We might jump to "out" early on error. Then filelist might not be set yet
and we might try to free garbage. Set it to the null_file early.

Signed-off-by: Mark Wielaard <[email protected]>
---
 libdw/ChangeLog           |  4 ++++
 libdw/dwarf_getsrclines.c | 23 ++++++++++++-----------
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index aa4d09c..e9b81f6 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,7 @@
+2015-06-06  Mark Wielaard  <[email protected]>
+
+       * dwarf_getsrclines.c (read_srclines): Initialize filelist early.
+
 2015-05-27  Mark Wielaard  <[email protected]>
 
        * encoded-value.h (read_encoded_value): Check data d_size contains
diff --git a/libdw/dwarf_getsrclines.c b/libdw/dwarf_getsrclines.c
index d49aedc..ba9649a 100644
--- a/libdw/dwarf_getsrclines.c
+++ b/libdw/dwarf_getsrclines.c
@@ -91,6 +91,18 @@ read_srclines (Dwarf *dbg,
   size_t nfilelist = 0;
   unsigned int ndirlist = 0;
 
+  struct filelist null_file =
+    {
+      .info =
+      {
+       .name = "???",
+       .mtime = 0,
+       .length = 0
+      },
+      .next = NULL
+    };
+  struct filelist *filelist = &null_file;
+
   /* If there are a large number of lines, files or dirs don't blow up
      the stack.  Stack allocate some entries, only dynamically malloc
      when more than MAX.  */
@@ -238,17 +250,6 @@ read_srclines (Dwarf *dbg,
   fl; })
 
   /* Now read the files.  */
-  struct filelist null_file =
-    {
-      .info =
-      {
-       .name = "???",
-       .mtime = 0,
-       .length = 0
-      },
-      .next = NULL
-    };
-  struct filelist *filelist = &null_file;
   nfilelist = 1;
 
   if (unlikely (linep >= lineendp))
-- 
2.1.0

Reply via email to