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:
Fred Kiefer 2010-09-12 16:34:22 +00:00
parent 26fcda321b
commit d08b23d9b0
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>
* Source/GSTheme.m:

View file

@ -746,10 +746,18 @@ Fills in all glyph holes up to last. only looking at levels below level
return;
length = [_textStorage length];
/* OPT: this can be done __much__ more efficiently */
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,7 +849,8 @@ Fills in all glyph holes up to last. only looking at levels below level
glyph_run_t *r;
unsigned int pos;
*isValidIndex = NO;
if (isValidIndex != NULL)
*isValidIndex = NO;
/* glyph '-1' is returned in other places as an "invalid" marker; this
way, we can say that it isn't valid without building all glyphs */
@ -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 */
return NSNullGlyph;
*isValidIndex = YES;
if (isValidIndex != NULL)
*isValidIndex = YES;
return r->glyphs[glyphIndex - pos].g;
}

View file

@ -118,6 +118,7 @@ static GSThemeInspector *sharedInspector = nil;
iv = [[NSImageView alloc] initWithFrame: frame];
[iv setImage: [[GSTheme theme] icon]];
[content addSubview: iv];
RELEASE(iv);
width = cFrame.size.width - 58;
tf = new_label([theme name]);
@ -159,6 +160,7 @@ static GSThemeInspector *sharedInspector = nil;
frame.origin.y = nameFrame.origin.y - frame.size.height - 25;
[view setFrame: frame];
[content addSubview: view];
RELEASE(view);
}
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
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.
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
reference a toolbar. */
- (NSArray *) paletteItemsWithToolbarItems: (NSArray *)items
@ -76,6 +76,7 @@
[newItem setEnabled: YES];
[newItem _layout];
[paletteItems addObject: newItem];
RELEASE(newItem);
}
NSDebugLLog(DEBUG_LEVEL, @"Generated palette items %@ from toolbar items %@",

View file

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

View file

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

View file

@ -1574,7 +1574,8 @@ typedef struct _GSButtonCellFlags
// encode button image source, if it exists...
if (bi != nil)
{
[aCoder encodeObject: bi forKey: @"NSAlternateImage"];
[aCoder encodeObject: bi forKey: @"NSAlternateImage"];
RELEASE(bi);
}
else if (_altImage != nil)
{

View file

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

View file

@ -135,7 +135,6 @@ static GSComboWindow *gsWindow = nil;
defer: (BOOL)flag
{
NSBox *box;
NSScrollView *scrollView;
NSRect borderRect;
self = [super initWithContentRect: contentRect
@ -156,52 +155,64 @@ static GSComboWindow *gsWindow = nil;
if (!ForceBrowser)
{
_tableView = [[GSComboBoxTableView alloc]
initWithFrame: NSMakeRect(0, 0, 100, 100)];
[_tableView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
//[_tableView setBackgroundColor: [NSColor whiteColor]];
[_tableView setDrawsGrid: NO];
[_tableView setAllowsEmptySelection: YES];
[_tableView setAllowsMultipleSelection: NO];
[_tableView setAutoresizesAllColumnsToFit: YES];
[_tableView setHeaderView: nil];
[_tableView setCornerView: nil];
[_tableView addTableColumn: [[NSTableColumn alloc] initWithIdentifier: @"content"]];
[[_tableView tableColumnWithIdentifier:@"content"] setDataCell: [[NSCell alloc] initTextCell: @""]];
[_tableView setDataSource: self];
[_tableView setDelegate: self];
[_tableView setAction: @selector(clickItem:)];
[_tableView setTarget: self];
scrollView = [[NSScrollView alloc] initWithFrame: NSMakeRect(borderRect.origin.x,
borderRect.origin.y,
borderRect.size.width,
borderRect.size.height)];
[scrollView setHasVerticalScroller: YES];
[scrollView setDocumentView: _tableView];
[box setContentView: scrollView];
[_tableView reloadData];
NSScrollView *scrollView;
NSTableColumn *column;
NSCell *cell;
_tableView = [[GSComboBoxTableView alloc]
initWithFrame: NSMakeRect(0, 0, 100, 100)];
[_tableView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
//[_tableView setBackgroundColor: [NSColor whiteColor]];
[_tableView setDrawsGrid: NO];
[_tableView setAllowsEmptySelection: YES];
[_tableView setAllowsMultipleSelection: NO];
[_tableView setAutoresizesAllColumnsToFit: YES];
[_tableView setHeaderView: nil];
[_tableView setCornerView: nil];
column = [[NSTableColumn alloc] initWithIdentifier: @"content"];
cell = [[NSCell alloc] initTextCell: @""];
[column setDataCell: cell];
RELEASE(cell);
[_tableView addTableColumn: column];
RELEASE(column);
[_tableView setDataSource: self];
[_tableView setDelegate: self];
[_tableView setAction: @selector(clickItem:)];
[_tableView setTarget: self];
scrollView = [[NSScrollView alloc] initWithFrame: NSMakeRect(borderRect.origin.x,
borderRect.origin.y,
borderRect.size.width,
borderRect.size.height)];
[scrollView setHasVerticalScroller: YES];
[scrollView setDocumentView: _tableView];
[box setContentView: scrollView];
RELEASE(scrollView);
[_tableView reloadData];
}
else
{
_browser = [[NSBrowser alloc] initWithFrame: NSMakeRect(borderRect.origin.x,
borderRect.origin.y,
borderRect.size.width,
borderRect.size.height)];
[_browser setMaxVisibleColumns: 1];
[_browser setTitled: NO];
[_browser setHasHorizontalScroller: NO];
[_browser setTarget: self];
[_browser setAction: @selector(clickItem:)];
[_browser setDelegate: self];
[_browser setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[_browser setAllowsEmptySelection: YES];
[_browser setAllowsMultipleSelection: NO];
[_browser setReusesColumns: YES];
// Create an empty matrix
[_browser loadColumnZero];
[box setContentView: _browser];
_browser = [[NSBrowser alloc] initWithFrame: NSMakeRect(borderRect.origin.x,
borderRect.origin.y,
borderRect.size.width,
borderRect.size.height)];
[_browser setMaxVisibleColumns: 1];
[_browser setTitled: NO];
[_browser setHasHorizontalScroller: NO];
[_browser setTarget: self];
[_browser setAction: @selector(clickItem:)];
[_browser setDelegate: self];
[_browser setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[_browser setAllowsEmptySelection: YES];
[_browser setAllowsMultipleSelection: NO];
[_browser setReusesColumns: YES];
// Create an empty matrix
[_browser loadColumnZero];
[box setContentView: _browser];
}
return self;
@ -1844,6 +1855,7 @@ static inline NSRect buttonCellFrameFromRect(NSRect cellRect)
[textObject scrollRangeToVisible: NSMakeRange(location, length)];
}
}
RELEASE(myString);
}
}

View file

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

View file

@ -419,15 +419,17 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
- (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)
{
RELEASE(self);
return nil;
}
if (!(self = [self init]))
return nil;
[self addRepresentation: rep];
RELEASE(rep);
@ -437,15 +439,17 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
- (id)initWithIconHandle:(void *)icon
{
// 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)
{
RELEASE(self);
return nil;
}
if (!(self = [self init]))
return nil;
[self addRepresentation: rep];
RELEASE(rep);
@ -454,15 +458,17 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
- (id) initWithContentsOfURL: (NSURL *)anURL
{
NSArray *array = [NSImageRep imageRepsWithContentsOfURL: anURL];
NSArray *array;
if (!(self = [self init]))
return nil;
array = [NSImageRep imageRepsWithContentsOfURL: anURL];
if (!array)
{
RELEASE(self);
return nil;
}
if (!(self = [self init]))
return nil;
_flags.dataRetained = YES;
[self addRepresentations: array];
@ -477,7 +483,6 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
return nil;
reps = [NSImageRep imageRepsWithPasteboard: pasteboard];
if (reps != nil)
[self addRepresentations: reps];
else

View file

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

View file

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

View file

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

View file

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