tests: dwfl-bug-fd-leak: Guard against null module addresses
authorPino Toscano <toscano.pino@tiscali.it>
Sat, 27 Jun 2015 16:33:37 +0000 (18:33 +0200)
committerMark Wielaard <mjw@redhat.com>
Sat, 27 Jun 2015 21:25:57 +0000 (23:25 +0200)
Do not crash if there is no module for the given address.

Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
tests/ChangeLog
tests/dwfl-bug-fd-leak.c

index 3461168..3e567b3 100644 (file)
@@ -1,3 +1,8 @@
+2015-06-27  Pino Toscano  <toscano.pino@tiscali.it>
+
+       * tests/dwfl-bug-fd-leak.c (elfutils_open): Check for null results of
+       dwfl_addrmodule.
+
 2015-06-26  Pino Toscano  <toscano.pino@tiscali.it>
 
        * tests/vdsosyms.c [!__linux__] (main): Mark argv as unused.
index 170a61a..bcbfb29 100644 (file)
@@ -65,7 +65,11 @@ elfutils_open (pid_t pid, Dwarf_Addr address)
     }
   else
     {
-      Elf *elf = dwfl_module_getelf (dwfl_addrmodule (dwfl, address), &bias);
+      Dwfl_Module *module = dwfl_addrmodule (dwfl, address);
+      if (module == NULL)
+       error (2, 0, "dwfl_addrmodule: no module available for 0x%" PRIx64 "",
+              address);
+      Elf *elf = dwfl_module_getelf (module, &bias);
       if (elf == NULL)
        error (2, 0, "dwfl_module_getelf: %s", dwfl_errmsg (-1));
     }