From c3fcd834b0b42f14c44d2f4829a34271b7ced282 Mon Sep 17 00:00:00 2001 From: Stefan Kalkowski Date: Thu, 3 May 2012 15:37:29 +0200 Subject: [PATCH] Fiasco.OC: check for leaks while thread creation When unmarshalling capabilities it is checked, whether a capability with the id was leaking, but this isn't done when creating a thread. Here the capability is transfered indirectly via the thread state object. This patch checks for old leakage capabilities while thread creation. --- base-foc/src/base/thread/thread_start.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/base-foc/src/base/thread/thread_start.cc b/base-foc/src/base/thread/thread_start.cc index 2739d8be05..c64a05b62a 100644 --- a/base-foc/src/base/thread/thread_start.cc +++ b/base-foc/src/base/thread/thread_start.cc @@ -61,6 +61,15 @@ void Thread_base::start() l4_utcb_tcr_u(state.utcb)->user[UTCB_TCR_BADGE] = state.id; l4_utcb_tcr_u(state.utcb)->user[UTCB_TCR_THREAD_OBJ] = (addr_t)this; + /* there might be leaks in the application */ + Cap_index *idx = cap_map()->find(state.id); + if (idx) { + idx->inc(); + PWRN("leaking capability idx=%p id=%x ref_cnt=%d", + idx, idx->id(), idx->dec()); + cap_map()->remove(idx); + } + /* we need to manually increase the reference counter here */ cap_map()->insert(state.id, state.kcap)->inc(); } catch(Cap_index_allocator::Region_conflict) {