diff --git a/ChangeLog b/ChangeLog index a5532ad95..a5b8d98ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-10-15 Richard Frith-Macdonald + + * Source/NSProcessInfo.m: Remove useless sysctl command. + * Source/NSMessagePort.m: Ensure port is not deallocated while + being invalidated. Fix memory leak of port lock. + * Source/NSSocketPort.m: Ensure port is not deallocated while + being invalidated. + 2008-11-15 Wolfgang Lux * Source/NSMessagePort.m (-invalidate, -removeHandle:): Fix diff --git a/Source/NSMessagePort.m b/Source/NSMessagePort.m index 027641300..c43eb3a23 100644 --- a/Source/NSMessagePort.m +++ b/Source/NSMessagePort.m @@ -1369,11 +1369,6 @@ typedef struct { - (void) dealloc { [self gcFinalize]; - if (_internal != 0) - { - DESTROY(name); - NSZoneFree(NSDefaultMallocZone(), _internal); - } [super dealloc]; } @@ -1390,6 +1385,13 @@ typedef struct { { NSDebugMLLog(@"NSMessagePort", @"NSMessagePort 0x%x finalized", self); [self invalidate]; + if (_internal != 0) + { + DESTROY(name); + NSFreeMapTable(handles); + RELEASE(myLock); + NSZoneFree(NSDefaultMallocZone(), _internal); + } } /* @@ -1571,11 +1573,8 @@ typedef struct { { if ([self isValid] == YES) { - /* Copy the lock into a local variable since the _internal structure - * may be freed during the call to [super invalidate] - */ - NSRecursiveLock *lock = ((internal*)_internal)->_myLock; - M_LOCK(lock); + RETAIN(self); + M_LOCK(myLock); if ([self isValid] == YES) { @@ -1592,31 +1591,21 @@ typedef struct { lDesc = -1; } - if (handles != 0) + handleArray = NSAllMapTableValues(handles); + i = [handleArray count]; + while (i-- > 0) { - handleArray = NSAllMapTableValues(handles); - i = [handleArray count]; - while (i-- > 0) - { - GSMessageHandle *handle; + GSMessageHandle *handle; - handle = [handleArray objectAtIndex: i]; - [handle invalidate]; - } - /* - * We permit mutual recursive invalidation, so the handles map - * may already have been destroyed. - */ - if (handles != 0) - { - NSFreeMapTable(handles); - handles = 0; - } + handle = [handleArray objectAtIndex: i]; + [handle invalidate]; } + [[NSMessagePortNameServer sharedInstance] removePort: self]; [super invalidate]; } - M_UNLOCK(lock); + M_UNLOCK(myLock); + RELEASE(self); } } @@ -1626,7 +1615,7 @@ typedef struct { { return YES; } - if ([anObject class] == [self class]) + if ([anObject class] == [self class] && [self isValid] && [anObject isValid]) { NSMessagePort *o = (NSMessagePort*)anObject; @@ -1720,11 +1709,8 @@ typedef struct { - (void) removeHandle: (GSMessageHandle*)handle { - /* Copy the lock into a local variable since the _internal structure - * may be freed during the call to [self invalidate] - */ - NSRecursiveLock *lock = ((internal*)_internal)->_myLock; - M_LOCK(lock); + RETAIN(self); + M_LOCK(myLock); if ([handle sendPort] == self) { if (handle->caller != YES) @@ -1749,7 +1735,8 @@ typedef struct { { [self invalidate]; } - M_UNLOCK(lock); + M_UNLOCK(myLock); + RELEASE(self); } /* diff --git a/Source/NSProcessInfo.m b/Source/NSProcessInfo.m index 92d496990..9ba0bccdf 100644 --- a/Source/NSProcessInfo.m +++ b/Source/NSProcessInfo.m @@ -1287,10 +1287,6 @@ static void determineOperatingSystem() { return val; } - else if (sysctlbyname("activecpu", &val, &len, 0, 0) == 0) - { - return val; - } return [self processorCount]; #else return [self processorCount]; diff --git a/Source/NSSocketPort.m b/Source/NSSocketPort.m index e36c39f0e..9767ac2de 100644 --- a/Source/NSSocketPort.m +++ b/Source/NSSocketPort.m @@ -1824,6 +1824,11 @@ static Class tcpPortClass; { NSDebugMLLog(@"NSPort", @"NSSocketPort 0x%x finalized", self); [self invalidate]; + if (handles != 0) + { + NSFreeMapTable(handles); + handles = 0; + } } /* @@ -2053,6 +2058,7 @@ static Class tcpPortClass; { if ([self isValid] == YES) { + RETAIN(self); M_LOCK(myLock); if ([self isValid] == YES) @@ -2089,15 +2095,6 @@ static Class tcpPortClass; [handle invalidate]; } - /* - * We permit mutual recursive invalidation, so the handles map - * may already have been destroyed. - */ - if (handles != 0) - { - NSFreeMapTable(handles); - handles = 0; - } } #if defined(__MINGW32__) if (events != 0) @@ -2110,6 +2107,7 @@ static Class tcpPortClass; [super invalidate]; } M_UNLOCK(myLock); + RELEASE(self); } } @@ -2254,6 +2252,7 @@ static Class tcpPortClass; */ - (void) removeHandle: (GSTcpHandle*)handle { + RETAIN(self); M_LOCK(myLock); if ([handle sendPort] == self) { @@ -2283,6 +2282,7 @@ static Class tcpPortClass; [self invalidate]; } M_UNLOCK(myLock); + RELEASE(self); } /*