Don't use deprecated +leak: method.

This commit is contained in:
rfm 2024-11-14 14:56:28 +00:00
parent 25505b2e67
commit 8b0543571b
4 changed files with 30 additions and 17 deletions

View file

@ -251,7 +251,7 @@ extern "C" {
/** Deprecated: use +leaked: instead. /** Deprecated: use +leaked: instead.
*/ */
+ (id) NS_RETURNS_RETAINED leak: (id)anObject ;//GS_DEPRECATED_FUNC; + (id) NS_RETURNS_RETAINED leak: (id)anObject GS_DEPRECATED_FUNC;
/** Deprecated: use +leaked: instead. /** Deprecated: use +leaked: instead.
*/ */

View file

@ -222,7 +222,8 @@ GSDomainFromDefaultLocale(void)
*/ */
if (saved == nil) if (saved == nil)
{ {
saved = [NSObject leak: dict]; saved = [dict copy];
[NSObject leaked: &saved];
} }
/** /**

View file

@ -114,6 +114,13 @@ static gs_mutex_t classLock = GS_MUTEX_INIT_STATIC;
return nil; return nil;
} }
+ (void) atExit
{
DESTROY(locCenter);
DESTROY(pubCenter);
DESTROY(netCenter);
}
/** /**
* Returns the default notification center ... a shared notification * Returns the default notification center ... a shared notification
* center for the local host. This is simply a convenience method * center for the local host. This is simply a convenience method
@ -125,6 +132,11 @@ static gs_mutex_t classLock = GS_MUTEX_INIT_STATIC;
return [self notificationCenterForType: NSLocalNotificationCenterType]; return [self notificationCenterForType: NSLocalNotificationCenterType];
} }
+ (void) initialize
{
[self registerAtExit];
}
/** /**
* Returns a notification center of the specified type.<br /> * Returns a notification center of the specified type.<br />
* The <code>NSLocalNotificationCenterType</code> provides a shared access to * The <code>NSLocalNotificationCenterType</code> provides a shared access to
@ -144,7 +156,7 @@ static gs_mutex_t classLock = GS_MUTEX_INIT_STATIC;
if (locCenter == nil) if (locCenter == nil)
{ {
GS_MUTEX_LOCK(classLock); GS_MUTEX_LOCK(classLock);
if (locCenter == nil) if (locCenter == nil && NO == [NSObject isExiting])
{ {
NS_DURING NS_DURING
{ {
@ -154,8 +166,7 @@ static gs_mutex_t classLock = GS_MUTEX_INIT_STATIC;
NSAllocateObject(self, 0, NSDefaultMallocZone()); NSAllocateObject(self, 0, NSDefaultMallocZone());
tmp->_centerLock = [NSRecursiveLock new]; tmp->_centerLock = [NSRecursiveLock new];
tmp->_type = RETAIN(NSLocalNotificationCenterType); tmp->_type = RETAIN(NSLocalNotificationCenterType);
locCenter = [NSObject leak: tmp]; locCenter = tmp;
[tmp release];
} }
NS_HANDLER NS_HANDLER
{ {
@ -173,7 +184,7 @@ static gs_mutex_t classLock = GS_MUTEX_INIT_STATIC;
if (pubCenter == nil) if (pubCenter == nil)
{ {
GS_MUTEX_LOCK(classLock); GS_MUTEX_LOCK(classLock);
if (pubCenter == nil) if (pubCenter == nil && NO == [NSObject isExiting])
{ {
NS_DURING NS_DURING
{ {
@ -183,8 +194,7 @@ static gs_mutex_t classLock = GS_MUTEX_INIT_STATIC;
NSAllocateObject(self, 0, NSDefaultMallocZone()); NSAllocateObject(self, 0, NSDefaultMallocZone());
tmp->_centerLock = [NSRecursiveLock new]; tmp->_centerLock = [NSRecursiveLock new];
tmp->_type = RETAIN(GSPublicNotificationCenterType); tmp->_type = RETAIN(GSPublicNotificationCenterType);
pubCenter = [NSObject leak: tmp]; pubCenter = tmp;
[tmp release];
} }
NS_HANDLER NS_HANDLER
{ {
@ -202,7 +212,7 @@ static gs_mutex_t classLock = GS_MUTEX_INIT_STATIC;
if (netCenter == nil) if (netCenter == nil)
{ {
GS_MUTEX_LOCK(classLock); GS_MUTEX_LOCK(classLock);
if (netCenter == nil) if (netCenter == nil && NO == [NSObject isExiting])
{ {
NS_DURING NS_DURING
{ {
@ -212,8 +222,7 @@ static gs_mutex_t classLock = GS_MUTEX_INIT_STATIC;
NSAllocateObject(self, 0, NSDefaultMallocZone()); NSAllocateObject(self, 0, NSDefaultMallocZone());
tmp->_centerLock = [NSRecursiveLock new]; tmp->_centerLock = [NSRecursiveLock new];
tmp->_type = RETAIN(GSNetworkNotificationCenterType); tmp->_type = RETAIN(GSNetworkNotificationCenterType);
netCenter = [NSObject leak: tmp]; netCenter = tmp;
[tmp release];
} }
NS_HANDLER NS_HANDLER
{ {

View file

@ -786,7 +786,7 @@ static inline BOOL timerInvalidated(NSTimer *t)
NSTimer *timer; NSTimer *timer;
SEL sel; SEL sel;
#ifdef RL_INTEGRATE_DISPATCH #ifdef RL_INTEGRATE_DISPATCH
GSMainQueueDrainer *drain; static GSMainQueueDrainer *drainer = nil;
#endif #endif
ctr = [NSNotificationCenter defaultCenter]; ctr = [NSNotificationCenter defaultCenter];
@ -810,17 +810,20 @@ static inline BOOL timerInvalidated(NSTimer *t)
[current addTimer: timer forMode: NSDefaultRunLoopMode]; [current addTimer: timer forMode: NSDefaultRunLoopMode];
#ifdef RL_INTEGRATE_DISPATCH #ifdef RL_INTEGRATE_DISPATCH
/* We leak the queue drainer, because it's integral part of RL if (nil == drainer)
* operations {
*/ /* We leak the queue drainer, because it's integral part of RL
drain = [NSObject leak: [[GSMainQueueDrainer new] autorelease]]; * operations
*/
drainer = [GSMainQueueDrainer new];
}
[current addEvent: [GSMainQueueDrainer mainQueueFileDescriptor] [current addEvent: [GSMainQueueDrainer mainQueueFileDescriptor]
#ifdef _WIN32 #ifdef _WIN32
type: ET_HANDLE type: ET_HANDLE
#else #else
type: ET_RDESC type: ET_RDESC
#endif #endif
watcher: drain watcher: drainer
forMode: NSDefaultRunLoopMode]; forMode: NSDefaultRunLoopMode];
#endif #endif