OSDN Git Service

linker: cleanup solist after unsuccessful read
authorDmitriy Ivanov <dimitry@google.com>
Fri, 6 Nov 2015 18:44:37 +0000 (10:44 -0800)
committerDmitriy Ivanov <dimitry@google.com>
Fri, 6 Nov 2015 18:44:37 +0000 (10:44 -0800)
Bug: http://b/25560017
Change-Id: I03c5a1d7aed34c480d341aacfb3b1afdfa037b99

linker/linker.cpp
tests/dlext_test.cpp

index 9f0b559..31ed1ec 100644 (file)
@@ -1523,6 +1523,8 @@ static bool load_library(LoadTask* task,
 
   // Read the ELF header and some of the segments.
   if (!task->read(realpath.c_str(), file_stat.st_size)) {
+    soinfo_free(si);
+    task->set_soinfo(nullptr);
     return false;
   }
 
index baf7eb5..c7d4d46 100644 (file)
@@ -169,6 +169,11 @@ TEST_F(DlExtTest, ExtInfoUseFdWithInvalidOffset) {
   ASSERT_TRUE(handle_ == nullptr);
   ASSERT_EQ("dlopen failed: \"" + lib_realpath + "\" has bad ELF magic", dlerror());
 
+  // Check if dlsym works after unsuccessful dlopen().
+  // Supply non-exiting one to make linker visit every soinfo.
+  void* sym = dlsym(RTLD_DEFAULT, "this_symbol_does_not_exist___");
+  ASSERT_TRUE(sym == nullptr);
+
   close(extinfo.library_fd);
 }