Correction to memory leak and crash when loading a gmodel.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@19270 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2004-05-08 15:42:27 +00:00
parent 8a4c8c5aa6
commit 9ff9c837fd
6 changed files with 61 additions and 45 deletions

View file

@ -1,3 +1,13 @@
2004-05-08 08:53 Gregory John Casamento <greg_casamento@yahoo.com>
* GModelDecoder.m: [GModelDecoder openGModel:]
Corrected issue which was causing a crash.
* GormDocument.m: Cleaned up a memory leak. Commented/Documented
the location / justification for all memory operations.
* Gorm.m: same as above. Also added code to [Gorm unhide:]
to prevent bringing forward the document window when
clicking on the app icon in test mode.
2004-05-06 21:21 Gregory John Casamento <greg_casamento@yahoo.com>
* GormDocument.m: [GormDocument selectClass:] do not switch if

View file

@ -261,14 +261,15 @@ static BOOL gormFileOwnerDecoded;
/* importing of legacy gmodel files.*/
- (id) openGModel: (NSString *)path
{
id obj, con;
id unarchiver;
id decoded;
NSEnumerator *enumerator;
NSArray *gmobjects;
NSArray *gmconnections;
Class u = gmodel_class(@"GMUnarchiver");
id obj, con;
id unarchiver;
id decoded;
NSEnumerator *enumerator;
NSArray *gmobjects;
NSArray *gmconnections;
Class u = gmodel_class(@"GMUnarchiver");
GormClassManager *classManager = [(Gorm *)NSApp classManager];
NSLog (@"Loading gmodel file %@...", path);
gormNibOwner = nil;
gormRealObject = nil;
@ -288,7 +289,7 @@ static BOOL gormFileOwnerDecoded;
[u decodeClassName: @"NSPopUpButtonCell" asClassName: @"GormNSPopUpButtonCell"];
[u decodeClassName: @"NSOutlineView" asClassName: @"GormNSOutlineView"];
unarchiver = [u unarchiverWithContentsOfFile: path];
unarchiver = RETAIN([u unarchiverWithContentsOfFile: path]);
if (!unarchiver)
{
NSLog(@"Failed to load gmodel file %@!!",path);
@ -359,7 +360,9 @@ static BOOL gormFileOwnerDecoded;
[self setName: nil forObject: obj];
}
if ([gormRealObject mainMenu])
[self setName: nil forObject: [gormRealObject mainMenu]];
{
[self setName: @"NSMenu" forObject: [gormRealObject mainMenu]];
}
}
else
{

28
Gorm.m
View file

@ -118,7 +118,7 @@ NSString *GormResizeCellNotification = @"GormResizeCellNotification";
[aCoder decodeValueOfObjCType: @encode(id) at: &theClass];
theFrame = [aCoder decodeRect];
//NSLog(@"Decoding proxy : %@", theClass);
RETAIN(theClass);
RETAIN(theClass); // release in dealloc of GSNibItem...
return self;
}
@ -130,7 +130,7 @@ NSString *GormResizeCellNotification = @"GormResizeCellNotification";
[aCoder decodeValueOfObjCType: @encode(unsigned int)
at: &autoresizingMask];
//NSLog(@"Decoding proxy : %@", theClass);
RETAIN(theClass);
RETAIN(theClass); // release in dealloc of GSNibItem...
return self;
}
@ -744,7 +744,7 @@ NSString *GormResizeCellNotification = @"GormResizeCellNotification";
[archiver encodeClassName: @"GormNSOutlineView"
intoClassName: @"NSOutlineView"];
[archiver encodeRootObject: activDoc];
data = RETAIN([archiver archiverData]);
data = RETAIN([archiver archiverData]); // Released below...
[activDoc endArchiving];
RELEASE(archiver);
@ -764,8 +764,8 @@ NSString *GormResizeCellNotification = @"GormResizeCellNotification";
if (testContainer != nil)
{
[testContainer awakeWithContext: nil
topLevelItems: nil];
RETAIN(testContainer);
topLevelItems: nil]; // FIXME: Top level items will leak...
RETAIN(testContainer); // released in endTesting:
}
/*
@ -1081,7 +1081,9 @@ NSString *GormResizeCellNotification = @"GormResizeCellNotification";
}
[nc postNotificationName: IBDidEndTestingInterfaceNotification
object: self];
RELEASE(pool);
return self;
}
}
@ -1135,7 +1137,7 @@ NSString *GormResizeCellNotification = @"GormResizeCellNotification";
}
else if ([name isEqual: IBWillCloseDocumentNotification])
{
RETAIN(obj);
RETAIN(obj); // release below...
[documents removeObjectIdenticalTo: obj];
AUTORELEASE(obj);
}
@ -1491,13 +1493,15 @@ NSString *GormResizeCellNotification = @"GormResizeCellNotification";
- (void) unhide: (id)sender
{
id document = [self activeDocument];
id window = [document window];
[super unhide: sender];
[(GormDocument *)document setDocumentActive: NO];
[(GormDocument *)document setDocumentActive: YES];
[window orderFront: sender];
if(!isTesting)
{
id document = [self activeDocument];
id window = [document window];
[(GormDocument *)document setDocumentActive: NO];
[(GormDocument *)document setDocumentActive: YES];
[window orderFront: sender];
}
}
@end

View file

@ -465,7 +465,6 @@ objectValueForTableColumn: (NSTableColumn *)tc
[super setObject: anObject];
ASSIGN(classManager, [(Gorm *)NSApp classManager]);
ASSIGN(currentClass, [object className]);
RETAIN(object);
[self _refreshView];
}

View file

@ -781,6 +781,7 @@
- (void) dealloc
{
RELEASE(classInformation);
RELEASE(customClassMap);
[super dealloc];
}
@ -961,7 +962,6 @@
NSArray *subclasses = [self subClassesOf: oldName];
[self _touch];
RETAIN(classInfo);
[classInformation removeObjectForKey: oldName];
[classInformation setObject: classInfo forKey: name];
@ -1093,7 +1093,7 @@
*/
RELEASE(classInformation);
classInformation = [NSMutableDictionary new];
RETAIN(classInformation);
RETAIN(classInformation); // released in dealloc...
enumerator = [dict keyEnumerator];
while ((key = [enumerator nextObject]) != nil)
{
@ -1416,7 +1416,7 @@
// copy the dictionary..
NSDebugLog(@"dictionary = %@",dict);
ASSIGN(customClassMap, [dict mutableCopy]);
RETAIN(customClassMap);
RETAIN(customClassMap); // released in dealloc
}
- (BOOL) isCustomClassMapEmpty

View file

@ -295,7 +295,7 @@ static NSImage *classesImage = nil;
[[self openEditorForObject: anObject] activate];
if ([anObject isKindOfClass: [NSWindow class]] == YES)
{
RETAIN(anObject);
// RETAIN(anObject);
[anObject setReleasedWhenClosed: NO];
}
}
@ -801,7 +801,7 @@ static NSImage *classesImage = nil;
- (void) detachObject: (id)anObject
{
NSString *name = RETAIN([self nameForObject: anObject]);
NSString *name = RETAIN([self nameForObject: anObject]); // released at end of method...
GormClassManager *cm = [self classManager];
unsigned count;
@ -1999,7 +1999,7 @@ static NSImage *classesImage = nil;
// the detach also does a release. Unfortunately, this causes a
// crash, so this extra retain is only here to stave off the
// release, so the autorelease can release the menu when it should.
RETAIN(obj);
RETAIN(obj); // extra retain to stave off autorelease...
}
}
@ -2615,10 +2615,11 @@ static NSImage *classesImage = nil;
- (void) setName: (NSString*)aName forObject: (id)object
{
id oldObject;
NSString *oldName;
id oldObject;
NSString *oldName;
NSMutableDictionary *cc = [classManager customClassMap];
NSString *className = nil;
NSString *className;
NSString *nameCopy;
if (object == nil)
{
@ -2678,15 +2679,15 @@ static NSImage *classesImage = nil;
{
return; /* Already have this name ... nothing to do */
}
RETAIN(object);
AUTORELEASE(object);
RETAIN(object); // the next operation will attempt to release the object, we need to retain it.
[nameTable removeObjectForKey: oldName];
NSMapRemove(objToName, (void*)object);
}
}
aName = [aName copy]; /* Make sure it's immutable */
[nameTable setObject: object forKey: aName];
NSMapInsert(objToName, (void*)object, (void*)aName);
nameCopy = [aName copy]; /* Make sure it's immutable */
[nameTable setObject: object forKey: nameCopy];
AUTORELEASE(object); // make sure that when it's removed from the table, it's released.
NSMapInsert(objToName, (void*)object, (void*)nameCopy);
if (oldName != nil)
{
[nameTable removeObjectForKey: oldName];
@ -2704,10 +2705,10 @@ static NSImage *classesImage = nil;
if(className != nil)
{
[cc removeObjectForKey: oldName];
[cc setObject: className forKey: aName];
[cc setObject: className forKey: nameCopy];
}
}
RELEASE(aName);
RELEASE(nameCopy); // release the copy of the name which we made...
}
- (void) setObject: (id)anObject isVisibleAtLaunch: (BOOL)flag
@ -2828,7 +2829,6 @@ static NSImage *classesImage = nil;
{
NSFileManager *mgr = [NSFileManager defaultManager];
NSString *path = [sp filename];
NSString *old = documentPath;
if ([path isEqual: documentPath] == NO
&& [mgr fileExistsAtPath: path] == YES)
@ -2839,12 +2839,12 @@ static NSImage *classesImage = nil;
[mgr removeFileAtPath: bPath handler: nil];
[mgr movePath: path toPath: bPath handler: nil];
}
documentPath = RETAIN(path);
// set the path...
ASSIGN(documentPath, path);
[self saveGormDocument: sender];
RELEASE(old);
return YES;
/* FIXME - need to update files window title etc */
}
return NO;
}
@ -3504,7 +3504,7 @@ objectValueForTableColumn: (NSTableColumn *)aTableColumn
NSString *name = [item getName];
// retain the name and add the action/outlet...
RETAIN(name);
// RETAIN(name);
if ([gov editType] == Actions)
{
NSString *formattedAction = [GormDocument formatAction: anObject];
@ -3580,7 +3580,7 @@ objectValueForTableColumn: (NSTableColumn *)aTableColumn
{
int row = 0;
RETAIN(item); // retain the new name
// RETAIN(item); // retain the new name
[classManager renameClassNamed: item newName: anObject];
[gov reloadData];
row = [gov rowForItem: anObject];