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_ */