Browse Source

libdl: first execute all destructors, then munmap library

Fix problem which might exist since 2011. We need to execute
the destructors for all dependant libraries, before munmap the
shared libraries, otherwise running destructor of a dependent library
might cause a segfault, trying to access an already unmapped memory.

This fixes for example segfaults while running php -m with ldap
module.

Reported-By: Dave Flogeras <dflogeras2@gmail.com>
Tested-By: Dave Flogeras <dflogeras2@gmail.com>
Waldemar Brodkorb 7 năm trước cách đây
mục cha
commit
14be0795f4
1 tập tin đã thay đổi với 5 bổ sung0 xóa
  1. 5 0
      ldso/libdl/libdl.c

+ 5 - 0
ldso/libdl/libdl.c

@@ -849,7 +849,12 @@ static int do_dlclose(void *vhandle, int need_fini)
 					DL_CALL_FUNC_AT_ADDR (dl_elf_fini, tpnt->loadaddr, (int (*)(void)));
 				}
 			}
+		}
+	}
 
+	for (j = 0; j < handle->init_fini.nlist; ++j) {
+		tpnt = handle->init_fini.init_fini[j];
+		if (tpnt->usage_count == 0) {
 			_dl_if_debug_print("unmapping: %s\n", tpnt->libname);
 			end = 0;
 			for (i = 0, ppnt = tpnt->ppnt;