Fixups for memory amangement and thread safety issues

This commit is contained in:
Richard Frith-Macdonald 2022-01-31 16:57:10 +00:00
parent f1b3144209
commit e9ed77fb68
2 changed files with 26 additions and 15 deletions

View file

@ -1,7 +1,14 @@
2022-01-31 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSURL.m:
Fix for git #235 reported by Sergei Golovin
Plus, make methods consistent in handling of clients.
Plus, make clientForHandle() thread-safe.
2022-01-30 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSPredicate.m:
Fix for git #233
Fix for git #233 by Larry Campbell
2022-01-15 Frederik Seiffert <frederik@algoriddim.com>

View file

@ -442,10 +442,10 @@ static id clientForHandle(void *data, NSURLHandle *hdl)
if (data != 0)
{
[clientsLock lock];
client = (id)NSMapGet((NSMapTable*)data, hdl);
client = RETAIN((id)NSMapGet((NSMapTable*)data, hdl));
[clientsLock unlock];
}
return client;
return AUTORELEASE(client);
}
/**
@ -2005,18 +2005,20 @@ static NSUInteger urlAlign;
{
id c = clientForHandle(_clients, sender);
RETAIN(self);
[sender removeClient: self];
if (c != nil)
{
[clientsLock lock];
NSMapRemove((NSMapTable*)_clients, (void*)sender);
[clientsLock unlock];
if ([c respondsToSelector:
@selector(URL:resourceDidFailLoadingWithReason:)])
{
[c URL: self resourceDidFailLoadingWithReason: reason];
}
[clientsLock lock];
NSMapRemove((NSMapTable*)_clients, (void*)sender);
[clientsLock unlock];
}
[sender removeClient: self];
RELEASE(self);
}
- (void) URLHandleResourceDidBeginLoading: (NSURLHandle*)sender
@ -2027,34 +2029,36 @@ static NSUInteger urlAlign;
{
id c = clientForHandle(_clients, sender);
RETAIN(self);
[sender removeClient: self];
if (c != nil)
{
[clientsLock lock];
NSMapRemove((NSMapTable*)_clients, (void*)sender);
[clientsLock unlock];
if ([c respondsToSelector: @selector(URLResourceDidCancelLoading:)])
{
[c URLResourceDidCancelLoading: self];
}
[clientsLock lock];
NSMapRemove((NSMapTable*)_clients, (void*)sender);
[clientsLock unlock];
}
[sender removeClient: self];
RELEASE(self);
}
- (void) URLHandleResourceDidFinishLoading: (NSURLHandle*)sender
{
id c = clientForHandle(_clients, sender);
IF_NO_GC([self retain];)
RETAIN(self);
[sender removeClient: self];
if (c != nil)
{
[clientsLock lock];
NSMapRemove((NSMapTable*)_clients, (void*)sender);
[clientsLock unlock];
if ([c respondsToSelector: @selector(URLResourceDidFinishLoading:)])
{
[c URLResourceDidFinishLoading: self];
}
[clientsLock lock];
NSMapRemove((NSMapTable*)_clients, (void*)sender);
[clientsLock unlock];
}
RELEASE(self);
}