noux: avoid dangling pointer

Issue #485
This commit is contained in:
Alexander Boettcher 2013-08-28 14:47:08 +02:00 committed by Norman Feske
parent 78c8145d9b
commit bbb9c6daec
2 changed files with 21 additions and 23 deletions

View File

@ -73,6 +73,8 @@ namespace Noux {
user = _users.first(); user = _users.first();
if (!user) if (!user)
break; break;
_users.remove(user);
} }
user->dissolve(*this); user->dissolve(*this);
} }

View File

@ -218,17 +218,18 @@ namespace Noux {
Region(*this, ds, size, offset, local_addr); Region(*this, ds, size, offset, local_addr);
/* register region as user of RAM dataspaces */ /* register region as user of RAM dataspaces */
Object_pool<Dataspace_info>::Guard info(_ds_registry.lookup_info(ds)); {
Object_pool<Dataspace_info>::Guard info(_ds_registry.lookup_info(ds));
if (info) {
if (info) { info->register_user(*region);
info->register_user(*region); } else {
} else { if (verbose_attach) {
if (verbose_attach) { PWRN("Trying to attach unknown dataspace type");
PWRN("Trying to attach unknown dataspace type"); PWRN(" ds_info@%p at 0x%lx size=%zd offset=0x%lx",
PWRN(" ds_info@%p at 0x%lx size=%zd offset=0x%lx", info.object(), (long)local_addr,
info.object(), (long)local_addr, Dataspace_client(ds).size(), (long)offset);
Dataspace_client(ds).size(), (long)offset); }
} }
} }
@ -244,8 +245,6 @@ namespace Noux {
void detach(Local_addr local_addr) void detach(Local_addr local_addr)
{ {
_rm.detach(local_addr);
Region *region = _lookup_region_by_addr(local_addr); Region *region = _lookup_region_by_addr(local_addr);
if (!region) { if (!region) {
PWRN("Attempt to detach unknown region at 0x%p", PWRN("Attempt to detach unknown region at 0x%p",
@ -255,11 +254,16 @@ namespace Noux {
_regions.remove(region); _regions.remove(region);
Object_pool<Dataspace_info>::Guard info(_ds_registry.lookup_info(region->ds)); {
if (info) Object_pool<Dataspace_info>::Guard info(_ds_registry.lookup_info(region->ds));
info->unregister_user(*region); if (info)
info->unregister_user(*region);
}
destroy(env()->heap(), region); destroy(env()->heap(), region);
_rm.detach(local_addr);
} }
Pager_capability add_client(Thread_capability thread) Pager_capability add_client(Thread_capability thread)
@ -291,15 +295,7 @@ namespace Noux {
inline void Rm_session_component::Region::dissolve(Dataspace_info &ds) inline void Rm_session_component::Region::dissolve(Dataspace_info &ds)
{ {
/*
* When this function is called, the 'ds' is already locked by the
* caller. To prevent 'detach' from taking the lock twice
* ('_ds_registry.lookup_info'), the temporarily release and re-acquire
* the lock.
*/
ds.release();
rm.detach(local_addr); rm.detach(local_addr);
ds.acquire();
} }
} }