diff --git a/base-foc/src/base/thread/thread_start.cc b/base-foc/src/base/thread/thread_start.cc index 2739d8be0..c64a05b62 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) {