From 2b269f2e4788e02c615ab744bf45cc4274dd1f3b Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 13 Nov 2013 01:47:08 +0100 Subject: [PATCH] unlock_memory_etc(): Fix address space reference leak unlock_memory_etc() is supposed to release the address space reference lock_memory_etc() acquired. It didn't do that, though. --- src/system/kernel/vm/vm.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 0fec8a24bd..c9ebda44ef 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -5352,6 +5352,8 @@ lock_memory_etc(team_id team, void* address, size_t numBytes, uint32 flags) return B_ERROR; AddressSpaceReadLocker addressSpaceLocker(addressSpace, true); + // We get a new address space reference here. The one we got above will + // be freed by unlock_memory_etc(). VMTranslationMap* map = addressSpace->TranslationMap(); status_t error = B_OK; @@ -5508,7 +5510,9 @@ unlock_memory_etc(team_id team, void* address, size_t numBytes, uint32 flags) if (addressSpace == NULL) return B_ERROR; - AddressSpaceReadLocker addressSpaceLocker(addressSpace, true); + AddressSpaceReadLocker addressSpaceLocker(addressSpace, false); + // Take over the address space reference. We don't unlock until we're + // done. VMTranslationMap* map = addressSpace->TranslationMap(); status_t error = B_OK; @@ -5594,7 +5598,7 @@ unlock_memory_etc(team_id team, void* address, size_t numBytes, uint32 flags) break; } - // get rid of the address space reference + // get rid of the address space reference lock_memory_etc() acquired addressSpace->Put(); return error;