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:
Richard Frith-MacDonald 2006-06-29 18:01:44 +00:00
parent 3aac50d1c4
commit 7d7cdcc9b6
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/GSString.m: fix bug getting Cstring.
* Source/NSNotificationQueue.m: fix mem leak in multithreaded apps.
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
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>
$Date$ $Revision$
@ -43,7 +44,8 @@
in the thread dictionary and accessed using the key below.
*/
static NSString* tkey = @"NotificationQueueListThreadKey";
static NSString* lkey = @"NotificationQueueListThreadKey";
static NSString* qkey = @"NotificationQueueThreadKey";
typedef struct {
@defs(NSNotificationQueue)
@ -67,11 +69,11 @@ currentList(void)
NSMutableDictionary *d;
d = GSCurrentThreadDictionary();
list = (NotificationQueueList*)[d objectForKey: tkey];
list = (NotificationQueueList*)[d objectForKey: lkey];
if (list == nil)
{
list = [NotificationQueueList new];
[d setObject: list forKey: tkey];
[d setObject: list forKey: lkey];
RELEASE(list); /* retained in dictionary. */
}
return list;
@ -79,6 +81,18 @@ currentList(void)
@implementation NotificationQueueList
- (void) dealloc
{
while (next != nil)
{
NotificationQueueList *tmp = next;
next = tmp->next;
RELEASE(tmp);
}
[super dealloc];
}
+ (void) registerQueue: (NSNotificationQueue*)q
{
NotificationQueueList *list;
@ -122,12 +136,12 @@ currentList(void)
{
NotificationQueueList *tmp = list->next;
[d setObject: tmp forKey: tkey];
[d setObject: tmp forKey: lkey];
RELEASE(tmp); /* retained in dictionary. */
}
else
{
[d removeObjectForKey: tkey];
[d removeObjectForKey: lkey];
}
}
else
@ -291,6 +305,14 @@ add_to_queue(NSNotificationQueueList *queue, NSNotification *notification,
0, NSDefaultMallocZone());
item = [item initWithNotificationCenter:
[NSNotificationCenter defaultCenter]];
if (item != nil)
{
NSMutableDictionary *d;
d = GSCurrentThreadDictionary();
[d setObject: item forKey: qkey];
RELEASE(item); /* retained in dictionary. */
}
}
return item;
}