This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix two failure condition checks in libdwfl/linux-kernel-modules.c.


In report_kernel () if find_kernel_elf () fails then fname hasn't been
allocated or already freed. Don't free it again.

Brackets around unlikely expression in report_kernel_archive were incorrect
making the check always succeed.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 libdwfl/ChangeLog              |    6 ++++++
 libdwfl/linux-kernel-modules.c |    6 +++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index bea55cf..896ae39 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,9 @@
+2012-12-11  Mark Wielaard  <mjw@redhat.com>
+
+	* linux-kernel-modules.c (report_kernel): Only free fname if
+	find_kernel_elf succeeds and allocates it.
+	(report_kernel_archive): Fix brackets around unlikely expression.
+
 2012-11-29  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
 	* argp-std.c: Update Copyright year.
diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c
index bafe53c..9bf5f25 100644
--- a/libdwfl/linux-kernel-modules.c
+++ b/libdwfl/linux-kernel-modules.c
@@ -225,12 +225,12 @@ report_kernel (Dwfl *dwfl, const char **release,
 	    mod->e_type = ET_DYN;
 	}
 
+      free (fname);
+
       if (!report || result < 0)
 	close (fd);
     }
 
-  free (fname);
-
   return result;
 }
 
@@ -247,7 +247,7 @@ report_kernel_archive (Dwfl *dwfl, const char **release,
   char *archive;
   if (unlikely ((*release)[0] == '/'
 		? asprintf (&archive, "%s/debug.a", *release)
-		: asprintf (&archive, MODULEDIRFMT "/debug.a", *release)) < 0)
+		: asprintf (&archive, MODULEDIRFMT "/debug.a", *release) < 0))
     return ENOMEM;
 
   int fd = try_kernel_name (dwfl, &archive, false);
-- 
1.7.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]