From 3347d08b79e9e1537d65a4614e33375a09393d07 Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Wed, 5 Dec 2018 17:10:17 +0100 Subject: [PATCH] ldso: cleanup if loading of 'Shared_object' fails This can happen, for example, during 'dlopen' if unresolved symbols are present. * Unload already loaded shared libraries * Delete dependencies * Flush initializer list (ctors) fixes #3073 --- repos/base/src/lib/ldso/dependency.cc | 10 +++++++++- repos/base/src/lib/ldso/include/init.h | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/repos/base/src/lib/ldso/dependency.cc b/repos/base/src/lib/ldso/dependency.cc index d7b016c7d8..783e6ee2e2 100644 --- a/repos/base/src/lib/ldso/dependency.cc +++ b/repos/base/src/lib/ldso/dependency.cc @@ -91,5 +91,13 @@ Linker::Root_object::Root_object(Env &env, Allocator &md_alloc, new (md_alloc) Dependency(env, md_alloc, linker_name(), this, _deps, DONT_KEEP); /* relocate and call constructors */ - Init::list()->initialize(bind, STAGE_SO); + try { + Init::list()->initialize(bind, STAGE_SO); + } catch (...) { + Init::list()->flush(); + while (Dependency *d = _deps.dequeue()) + destroy(_md_alloc, d); + + throw; + } } diff --git a/repos/base/src/lib/ldso/include/init.h b/repos/base/src/lib/ldso/include/init.h index aaf5688275..ae6558455b 100644 --- a/repos/base/src/lib/ldso/include/init.h +++ b/repos/base/src/lib/ldso/include/init.h @@ -132,6 +132,15 @@ struct Linker::Init : List in_progress = false; } + + void flush() + { + while (Object *obj = first()) + remove(obj); + + in_progress = false; + restart = false; + } }; #endif /* _INCLUDE__INIT_H_ */