Fix leak of NSNotificationQueue in each thread created.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@23116 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2006-06-29 18:01:44 +00:00
parent 5ee536df00
commit 5e3615df79
2 changed files with 29 additions and 6 deletions

View file

@ -2,6 +2,7 @@
* Source/Tools/gdnc.m: Don't try to trap SIGPROF * Source/Tools/gdnc.m: Don't try to trap SIGPROF
* Source/GSString.m: fix bug getting Cstring. * Source/GSString.m: fix bug getting Cstring.
* Source/NSNotificationQueue.m: fix mem leak in multithreaded apps.
2006-06-27 Richard Frith-Macdonald <rfm@gnu.org> 2006-06-27 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -21,7 +21,8 @@
You should have received a copy of the GNU Library General Public You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
<title>NSNotificationQueue class reference</title> <title>NSNotificationQueue class reference</title>
$Date$ $Revision$ $Date$ $Revision$
@ -43,7 +44,8 @@
in the thread dictionary and accessed using the key below. in the thread dictionary and accessed using the key below.
*/ */
static NSString* tkey = @"NotificationQueueListThreadKey"; static NSString* lkey = @"NotificationQueueListThreadKey";
static NSString* qkey = @"NotificationQueueThreadKey";
typedef struct { typedef struct {
@defs(NSNotificationQueue) @defs(NSNotificationQueue)
@ -67,11 +69,11 @@ currentList(void)
NSMutableDictionary *d; NSMutableDictionary *d;
d = GSCurrentThreadDictionary(); d = GSCurrentThreadDictionary();
list = (NotificationQueueList*)[d objectForKey: tkey]; list = (NotificationQueueList*)[d objectForKey: lkey];
if (list == nil) if (list == nil)
{ {
list = [NotificationQueueList new]; list = [NotificationQueueList new];
[d setObject: list forKey: tkey]; [d setObject: list forKey: lkey];
RELEASE(list); /* retained in dictionary. */ RELEASE(list); /* retained in dictionary. */
} }
return list; return list;
@ -79,6 +81,18 @@ currentList(void)
@implementation NotificationQueueList @implementation NotificationQueueList
- (void) dealloc
{
while (next != nil)
{
NotificationQueueList *tmp = next;
next = tmp->next;
RELEASE(tmp);
}
[super dealloc];
}
+ (void) registerQueue: (NSNotificationQueue*)q + (void) registerQueue: (NSNotificationQueue*)q
{ {
NotificationQueueList *list; NotificationQueueList *list;
@ -122,12 +136,12 @@ currentList(void)
{ {
NotificationQueueList *tmp = list->next; NotificationQueueList *tmp = list->next;
[d setObject: tmp forKey: tkey]; [d setObject: tmp forKey: lkey];
RELEASE(tmp); /* retained in dictionary. */ RELEASE(tmp); /* retained in dictionary. */
} }
else else
{ {
[d removeObjectForKey: tkey]; [d removeObjectForKey: lkey];
} }
} }
else else
@ -291,6 +305,14 @@ add_to_queue(NSNotificationQueueList *queue, NSNotification *notification,
0, NSDefaultMallocZone()); 0, NSDefaultMallocZone());
item = [item initWithNotificationCenter: item = [item initWithNotificationCenter:
[NSNotificationCenter defaultCenter]]; [NSNotificationCenter defaultCenter]];
if (item != nil)
{
NSMutableDictionary *d;
d = GSCurrentThreadDictionary();
[d setObject: item forKey: qkey];
RELEASE(item); /* retained in dictionary. */
}
} }
return item; return item;
} }