From ab1489c970b71dda5bc7c6462a4f68b46d363e86 Mon Sep 17 00:00:00 2001 From: rfm Date: Wed, 6 Sep 2006 15:12:03 +0000 Subject: [PATCH] Thread safetly fix suggested by Wim git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@23402 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 6 ++++++ Source/NSConnection.m | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index fe47d103e..50d5912d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-09-06 Richard Frith-Macdonald + + * Source/NSConnection.m: ([release]) protect with connection table + lock to prevent an other thread grabbing the connection while we + are deallocating it. Bug reported by Wim Oudshoorn. + 2006-08-28 Adam Fedor * Version 1.13.0 diff --git a/Source/NSConnection.m b/Source/NSConnection.m index 12161781a..d2ee860cb 100644 --- a/Source/NSConnection.m +++ b/Source/NSConnection.m @@ -1282,15 +1282,22 @@ static NSLock *cached_proxies_gate = nil; /* * If this would cause the connection to be deallocated then we * must perform all necessary work (done in [-gcFinalize]). + * * We bracket the code with a retain and release so that any * retain/release pairs in the code won't cause recursion. + * + * We lock the connection table while checking, to prevent + * another thread from grabbing this connection while we are + * finalizing/deallocating it. */ + M_LOCK(connection_table_gate); if ([self retainCount] == 1) { [super retain]; [self gcFinalize]; [super release]; } + M_UNLOCK(connection_table_gate); [super release]; }