First batch of corrections based on David's static analysis.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@31337 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2010-09-12 16:34:22 +00:00
parent 82ac6117e8
commit 30240921b4
15 changed files with 151 additions and 73 deletions

View file

@ -1,3 +1,31 @@
2010-09-12 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSApplication.m (+detachDrawingThread:...): Correct the
creation of the NSInvocation.
* Source/NSTableView.m (-mouseDown:): Free the auto release pool
and the create object when returning out of the method.
* Source/NSButtonCell.m (-encodeWithCoder:): Free the temporary
NSButtonImageSource.
* Source/NSCachedImageRep.m (-draw): Free the temporary
NSBitmapImageRep.
* Source/NSComboBoxCell.m (-initWithContentRect:...): Free the
NSScrollView, the NSTableColumn and the NSCell.
* Source/NSComboBoxCell.m (-textDidChange:): Free the temporary string.
* Source/NSDataLinkPanel.m (+sharedDataLinkPanel): Free the
controller but keep the panel.
* Source/NSImage.m (-initWithIconHandle:, -initWithBitmapHandle:):
Restructure initialisation order.
* Source/NSLayoutManager.m (-rulerMarkersForTextView:...): Don't
leak the created marker.
* Source/NSMenu.m (-copyWithZone:): Don't leak the copied menu
items.
* Source/GSThemeInspector.m (-update:): Release the views
after adding them to the hierarchy.
* Source/GSToolbarView.m (initSystemExtensionsColors): Don't leak
the colors dictionary.
* Source/GSToolbarCustomizationPalette.m
(-paletteItemsWithToolbarItems:): Release the copied toolbar items.
2010-09-09 Eric Wasylishen <ewasylishen@gmail.com> 2010-09-09 Eric Wasylishen <ewasylishen@gmail.com>
* Source/GSTheme.m: * Source/GSTheme.m:

View file

@ -746,10 +746,18 @@ Fills in all glyph holes up to last. only looking at levels below level
return; return;
length = [_textStorage length]; length = [_textStorage length];
/* OPT: this can be done __much__ more efficiently */
while (glyphs->glyph_length <= last && (glyphs->char_length < length || !glyphs->complete)) while (glyphs->glyph_length <= last && (glyphs->char_length < length || !glyphs->complete))
{ {
[self _generateGlyphsUpToCharacter: glyphs->char_length]; // Make an estimate for the character position
unsigned int char_last;
if (glyphs->glyph_length == 0)
char_last = last;
else
char_last = glyphs->char_length + 1 +
(last - glyphs->glyph_length) * (glyphs->char_length / (glyphs->glyph_length + 1));
[self _generateGlyphsUpToCharacter: char_last];
} }
} }
@ -841,6 +849,7 @@ Fills in all glyph holes up to last. only looking at levels below level
glyph_run_t *r; glyph_run_t *r;
unsigned int pos; unsigned int pos;
if (isValidIndex != NULL)
*isValidIndex = NO; *isValidIndex = NO;
/* glyph '-1' is returned in other places as an "invalid" marker; this /* glyph '-1' is returned in other places as an "invalid" marker; this
@ -862,7 +871,9 @@ Fills in all glyph holes up to last. only looking at levels below level
if (!r || !r->glyphs) /* shouldn't happen */ if (!r || !r->glyphs) /* shouldn't happen */
return NSNullGlyph; return NSNullGlyph;
if (isValidIndex != NULL)
*isValidIndex = YES; *isValidIndex = YES;
return r->glyphs[glyphIndex - pos].g; return r->glyphs[glyphIndex - pos].g;
} }

View file

@ -118,6 +118,7 @@ static GSThemeInspector *sharedInspector = nil;
iv = [[NSImageView alloc] initWithFrame: frame]; iv = [[NSImageView alloc] initWithFrame: frame];
[iv setImage: [[GSTheme theme] icon]]; [iv setImage: [[GSTheme theme] icon]];
[content addSubview: iv]; [content addSubview: iv];
RELEASE(iv);
width = cFrame.size.width - 58; width = cFrame.size.width - 58;
tf = new_label([theme name]); tf = new_label([theme name]);
@ -159,6 +160,7 @@ static GSThemeInspector *sharedInspector = nil;
frame.origin.y = nameFrame.origin.y - frame.size.height - 25; frame.origin.y = nameFrame.origin.y - frame.size.height - 25;
[view setFrame: frame]; [view setFrame: frame];
[content addSubview: view]; [content addSubview: view];
RELEASE(view);
} }
details = [[theme infoDictionary] objectForKey: @"GSThemeDetails"]; details = [[theme infoDictionary] objectForKey: @"GSThemeDetails"];

View file

@ -57,7 +57,7 @@
/* If the toolbar item has a custom view and the item is in use in the /* If the toolbar item has a custom view and the item is in use in the
toolbar, this view has already a superview. We need to make a copy of it toolbar, this view has already a superview. We need to make a copy of it
in order to be able to put it in the customization view. in order to be able to put it in the customization view.
As a safety measure, we makes a copy of all toolbar items, thereby of all As a safety measure, we make a copy of all toolbar items, thereby of all
views. This ensures the toolbar items displayed in the palette don't views. This ensures the toolbar items displayed in the palette don't
reference a toolbar. */ reference a toolbar. */
- (NSArray *) paletteItemsWithToolbarItems: (NSArray *)items - (NSArray *) paletteItemsWithToolbarItems: (NSArray *)items
@ -76,6 +76,7 @@
[newItem setEnabled: YES]; [newItem setEnabled: YES];
[newItem _layout]; [newItem _layout];
[paletteItems addObject: newItem]; [paletteItems addObject: newItem];
RELEASE(newItem);
} }
NSDebugLLog(DEBUG_LEVEL, @"Generated palette items %@ from toolbar items %@", NSDebugLLog(DEBUG_LEVEL, @"Generated palette items %@ from toolbar items %@",

View file

@ -119,6 +119,7 @@ static void initSystemExtensionsColors(void)
changed = YES; changed = YES;
} }
RELEASE(colors);
if (changed) if (changed)
[SystemExtensionsColors writeToFile: nil]; [SystemExtensionsColors writeToFile: nil];

View file

@ -753,7 +753,7 @@ static NSSize scaledIconSizeForSize(NSSize imageSize)
{ {
NSInvocation *inv; NSInvocation *inv;
inv = [[NSInvocation alloc] inv = [NSInvocation
invocationWithMethodSignature: invocationWithMethodSignature:
[target methodSignatureForSelector: selector]]; [target methodSignatureForSelector: selector]];
[inv setTarget: target]; [inv setTarget: target];
@ -762,7 +762,6 @@ static NSSize scaledIconSizeForSize(NSSize imageSize)
[NSThread detachNewThreadSelector: @selector(_invokeWithAutoreleasePool:) [NSThread detachNewThreadSelector: @selector(_invokeWithAutoreleasePool:)
toTarget: self toTarget: self
withObject: inv]; withObject: inv];
RELEASE(inv);
} }
/** /**

View file

@ -1575,6 +1575,7 @@ typedef struct _GSButtonCellFlags
if (bi != nil) if (bi != nil)
{ {
[aCoder encodeObject: bi forKey: @"NSAlternateImage"]; [aCoder encodeObject: bi forKey: @"NSAlternateImage"];
RELEASE(bi);
} }
else if (_altImage != nil) else if (_altImage != nil)
{ {

View file

@ -203,6 +203,7 @@
[view unlockFocus]; [view unlockFocus];
[rep draw]; [rep draw];
RELEASE(rep);
} }
return YES; return YES;

View file

@ -135,7 +135,6 @@ static GSComboWindow *gsWindow = nil;
defer: (BOOL)flag defer: (BOOL)flag
{ {
NSBox *box; NSBox *box;
NSScrollView *scrollView;
NSRect borderRect; NSRect borderRect;
self = [super initWithContentRect: contentRect self = [super initWithContentRect: contentRect
@ -156,6 +155,10 @@ static GSComboWindow *gsWindow = nil;
if (!ForceBrowser) if (!ForceBrowser)
{ {
NSScrollView *scrollView;
NSTableColumn *column;
NSCell *cell;
_tableView = [[GSComboBoxTableView alloc] _tableView = [[GSComboBoxTableView alloc]
initWithFrame: NSMakeRect(0, 0, 100, 100)]; initWithFrame: NSMakeRect(0, 0, 100, 100)];
[_tableView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; [_tableView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
@ -166,8 +169,15 @@ static GSComboWindow *gsWindow = nil;
[_tableView setAutoresizesAllColumnsToFit: YES]; [_tableView setAutoresizesAllColumnsToFit: YES];
[_tableView setHeaderView: nil]; [_tableView setHeaderView: nil];
[_tableView setCornerView: nil]; [_tableView setCornerView: nil];
[_tableView addTableColumn: [[NSTableColumn alloc] initWithIdentifier: @"content"]];
[[_tableView tableColumnWithIdentifier:@"content"] setDataCell: [[NSCell alloc] initTextCell: @""]]; column = [[NSTableColumn alloc] initWithIdentifier: @"content"];
cell = [[NSCell alloc] initTextCell: @""];
[column setDataCell: cell];
RELEASE(cell);
[_tableView addTableColumn: column];
RELEASE(column);
[_tableView setDataSource: self]; [_tableView setDataSource: self];
[_tableView setDelegate: self]; [_tableView setDelegate: self];
[_tableView setAction: @selector(clickItem:)]; [_tableView setAction: @selector(clickItem:)];
@ -180,6 +190,7 @@ static GSComboWindow *gsWindow = nil;
[scrollView setHasVerticalScroller: YES]; [scrollView setHasVerticalScroller: YES];
[scrollView setDocumentView: _tableView]; [scrollView setDocumentView: _tableView];
[box setContentView: scrollView]; [box setContentView: scrollView];
RELEASE(scrollView);
[_tableView reloadData]; [_tableView reloadData];
} }
@ -1844,6 +1855,7 @@ static inline NSRect buttonCellFrameFromRect(NSRect cellRect)
[textObject scrollRangeToVisible: NSMakeRange(location, length)]; [textObject scrollRangeToVisible: NSMakeRange(location, length)];
} }
} }
RELEASE(myString);
} }
} }

View file

@ -110,10 +110,9 @@ static NSDataLinkPanel *_sharedDataLinkPanel;
if (_sharedDataLinkPanel == nil) if (_sharedDataLinkPanel == nil)
{ {
id controller = [[GSDataLinkPanelController alloc] init]; id controller = [[GSDataLinkPanelController alloc] init];
_sharedDataLinkPanel = [controller panel]; ASSIGN(_sharedDataLinkPanel, [controller panel]);
[_sharedDataLinkPanel setDelegate: controller]; RELEASE(controller);
} }
NSLog(@"%@",_sharedDataLinkPanel);
return _sharedDataLinkPanel; return _sharedDataLinkPanel;
} }

View file

@ -419,15 +419,17 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
- (id) initWithBitmapHandle: (void *)bitmap - (id) initWithBitmapHandle: (void *)bitmap
{ {
NSImageRep *rep = [[NSBitmapImageRep alloc] initWithBitmapHandle: bitmap]; NSImageRep *rep;
if (!(self = [self init]))
return nil;
rep = [[NSBitmapImageRep alloc] initWithBitmapHandle: bitmap];
if (rep == nil) if (rep == nil)
{ {
RELEASE(self); RELEASE(self);
return nil; return nil;
} }
if (!(self = [self init]))
return nil;
[self addRepresentation: rep]; [self addRepresentation: rep];
RELEASE(rep); RELEASE(rep);
@ -437,15 +439,17 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
- (id)initWithIconHandle:(void *)icon - (id)initWithIconHandle:(void *)icon
{ {
// Only needed on MS Windows // Only needed on MS Windows
NSImageRep *rep = [[NSBitmapImageRep alloc] initWithIconHandle: icon]; NSImageRep *rep;
if (!(self = [self init]))
return nil;
rep = [[NSBitmapImageRep alloc] initWithIconHandle: icon];
if (rep == nil) if (rep == nil)
{ {
RELEASE(self); RELEASE(self);
return nil; return nil;
} }
if (!(self = [self init]))
return nil;
[self addRepresentation: rep]; [self addRepresentation: rep];
RELEASE(rep); RELEASE(rep);
@ -454,15 +458,17 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
- (id) initWithContentsOfURL: (NSURL *)anURL - (id) initWithContentsOfURL: (NSURL *)anURL
{ {
NSArray *array = [NSImageRep imageRepsWithContentsOfURL: anURL]; NSArray *array;
if (!(self = [self init]))
return nil;
array = [NSImageRep imageRepsWithContentsOfURL: anURL];
if (!array) if (!array)
{ {
RELEASE(self); RELEASE(self);
return nil; return nil;
} }
if (!(self = [self init]))
return nil;
_flags.dataRetained = YES; _flags.dataRetained = YES;
[self addRepresentations: array]; [self addRepresentations: array];
@ -477,7 +483,6 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
return nil; return nil;
reps = [NSImageRep imageRepsWithPasteboard: pasteboard]; reps = [NSImageRep imageRepsWithPasteboard: pasteboard];
if (reps != nil) if (reps != nil)
[self addRepresentations: reps]; [self addRepresentations: reps];
else else

View file

@ -1768,6 +1768,7 @@ dictionary.
imageOrigin: NSMakePoint(0, 0)]; imageOrigin: NSMakePoint(0, 0)];
[marker setRepresentedObject: tab]; [marker setRepresentedObject: tab];
[markers addObject: marker]; [markers addObject: marker];
RELEASE(marker);
} }
return markers; return markers;

View file

@ -1690,8 +1690,9 @@ static BOOL menuBarVisible = YES;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
// This works because the copy on NSMenuItem sets the menu to nil!!! // This works because the copy on NSMenuItem sets the menu to nil!!!
[new insertItem: [[_items objectAtIndex: i] copyWithZone: zone] NSMenuItem *item = [[_items objectAtIndex: i] copyWithZone: zone];
atIndex: i]; [new insertItem: item atIndex: i];
RELEASE(item);
} }
return new; return new;

View file

@ -3740,6 +3740,8 @@ if (currentRow >= 0 && currentRow < _numberOfRows) \
{ {
if ([self _startDragOperationWithEvent: theEvent]) if ([self _startDragOperationWithEvent: theEvent])
{ {
RELEASE(oldSelectedRows);
IF_NO_GC(DESTROY(arp));
return; return;
} }
else else

View file

@ -1581,22 +1581,36 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{ {
NSToolbarItem *new = [[NSToolbarItem allocWithZone: zone] NSToolbarItem *new = [[NSToolbarItem allocWithZone: zone]
initWithItemIdentifier: _itemIdentifier]; initWithItemIdentifier: _itemIdentifier];
NSString *toolTip;
NSImage *image;
NSString *label;
NSMenuItem *item;
// Copy all items individually... // Copy all items individually...
[new setTarget: [self target]]; [new setTarget: [self target]];
[new setAction: [self action]]; [new setAction: [self action]];
[new setToolTip: [[self toolTip] copyWithZone: zone]];
toolTip = [[self toolTip] copyWithZone: zone];
[new setToolTip: toolTip];
RELEASE(toolTip);
[new setTag: [self tag]]; [new setTag: [self tag]];
[new setImage: [[self image] copyWithZone: zone]]; image = [[self image] copyWithZone: zone];
[new setImage: image];
RELEASE(image);
[new setEnabled: [self isEnabled]]; [new setEnabled: [self isEnabled]];
[new setPaletteLabel: [[self paletteLabel] copyWithZone: zone]]; label = [[self paletteLabel] copyWithZone: zone];
[new setLabel: [[self label] copyWithZone: zone]]; [new setPaletteLabel: label];
RELEASE(label);
label = [[self label] copyWithZone: zone];
[new setLabel: label];
RELEASE(label);
[new setMinSize: [self minSize]]; [new setMinSize: [self minSize]];
[new setMaxSize: [self maxSize]]; [new setMaxSize: [self maxSize]];
[new setAutovalidates: [self autovalidates]]; [new setAutovalidates: [self autovalidates]];
[new setVisibilityPriority: [self visibilityPriority]]; [new setVisibilityPriority: [self visibilityPriority]];
[new setMenuFormRepresentation: [[self menuFormRepresentation] item = [[self menuFormRepresentation] copyWithZone: zone];
copyWithZone: zone]]; [new setMenuFormRepresentation: item];
RELEASE(item);
if ([self view] != nil) if ([self view] != nil)
{ {