# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1326749051 0 # Node ID 030e9bddc1c9d35e49a7bab17aada730b6b6065d # Parent 4a9c574d5c173499ddbdec13ce4f3c5cb91b8b96 Fixed some potential Objective-C memory leaks on Mac reported by XCode 4.2.1. Trying to track down an autorelease crash on Lion using dw_main_quit(). diff -r 4a9c574d5c17 -r 030e9bddc1c9 dwtest.c --- a/dwtest.c Sun Jan 15 22:36:41 2012 +0000 +++ b/dwtest.c Mon Jan 16 21:24:11 2012 +0000 @@ -704,7 +704,7 @@ /* Make sure the side area is cleared */ dw_color_foreground_set(DW_CLR_WHITE); - dw_draw_rect(0, text1pm, DW_DRAW_FILL, 0, 0, DW_PIXMAP_WIDTH(text1pm), DW_PIXMAP_HEIGHT(text1pm)); + dw_draw_rect(0, text1pm, DW_DRAW_FILL, 0, 0, (int)DW_PIXMAP_WIDTH(text1pm), (int)DW_PIXMAP_HEIGHT(text1pm)); /* Destroy the old pixmaps */ dw_pixmap_destroy(old1); @@ -1366,7 +1366,7 @@ dw_signal_connect( checkable_menuitem, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(menu_callback), (void *)"checkable"); noncheckable_menuitem = dw_menu_append_item( changeable_menu, "~Non-checkable Menu Item", NONCHECKABLE_MENUITEMID, 0, TRUE, FALSE, 0 ); dw_signal_connect( noncheckable_menuitem, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(menu_callback), (void *)"non-checkable"); - menuitem = dw_menu_append_item( changeable_menu, "~Disabled menu Item", 2003, DW_MIS_DISABLED|DW_MIS_CHECKED, TRUE, TRUE, 0 ); + dw_menu_append_item( changeable_menu, "~Disabled menu Item", 2003, DW_MIS_DISABLED|DW_MIS_CHECKED, TRUE, TRUE, 0 ); /* seperator */ dw_menu_append_item( changeable_menu, DW_MENU_SEPARATOR, 3999, 0, TRUE, FALSE, 0 ); menuitem = dw_menu_append_item( changeable_menu, "~Menu Items Disabled", 2009, 0, TRUE, TRUE, 0 ); diff -r 4a9c574d5c17 -r 030e9bddc1c9 mac/dw.m --- a/mac/dw.m Sun Jan 15 22:36:41 2012 +0000 +++ b/mac/dw.m Mon Jan 16 21:24:11 2012 +0000 @@ -553,7 +553,7 @@ [NSGraphicsContext saveGraphicsState]; [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:bltdest] graphicsPort] flipped:YES]]; - [[NSDictionary alloc] initWithObjectsAndKeys:bltdest, NSGraphicsContextDestinationAttributeName, nil]; + [[[NSDictionary alloc] initWithObjectsAndKeys:bltdest, NSGraphicsContextDestinationAttributeName, nil] autorelease]; } else { @@ -2268,9 +2268,9 @@ if(self) { - textfield = [[NSTextField alloc] init]; + textfield = [[[NSTextField alloc] init] autorelease]; [self addSubview:textfield]; - stepper = [[DWStepper alloc] init]; + stepper = [[[DWStepper alloc] init] autorelease]; [self addSubview:stepper]; [stepper setParent:self]; [stepper setTextfield:textfield]; @@ -3139,7 +3139,7 @@ /* Handle file types */ if(ext) { - NSArray* fileTypes = [[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil]; + NSArray* fileTypes = [[[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil] autorelease]; [openDlg setAllowedFileTypes:fileTypes]; } @@ -3176,7 +3176,7 @@ /* Handle file types */ if(ext) { - NSArray* fileTypes = [[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil]; + NSArray* fileTypes = [[[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil] autorelease]; [saveDlg setAllowedFileTypes:fileTypes]; } @@ -3881,7 +3881,7 @@ void API dw_entryfield_set_limit(HWND handle, ULONG limit) { DWEntryField *entry = handle; - DWEntryFieldFormatter *formatter = [[DWEntryFieldFormatter alloc] init]; + DWEntryFieldFormatter *formatter = [[[DWEntryFieldFormatter alloc] init] autorelease]; [formatter setMaximumLength:(int)limit]; [[entry cell] setFormatter:formatter]; @@ -3983,8 +3983,6 @@ [stepper setMaxValue:65536]; [stepper setIntValue:atoi(text)]; [textfield takeIntValueFrom:stepper]; - [stepper autorelease]; - [textfield autorelease]; return spinbutton; } @@ -4296,7 +4294,7 @@ [cont setHeaderView:nil]; int type = DW_CFA_STRING; [cont setup]; - NSTableColumn *column = [[NSTableColumn alloc] init]; + NSTableColumn *column = [[[NSTableColumn alloc] init] autorelease]; [column setEditable:NO]; [cont addTableColumn:column]; [cont addColumn:column andType:type]; @@ -5148,6 +5146,7 @@ /* Figure out the value of what they returned */ CGFloat red, green, blue; [color getRed:&red green:&green blue:&blue alpha:NULL]; + [color release]; value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255)); return value; } @@ -5831,7 +5830,7 @@ DWContainer *cont = _cont_new(cid, multi); NSScrollView *scrollview = [cont scrollview]; [scrollview setHasHorizontalScroller:YES]; - NSTableHeaderView *header = [[NSTableHeaderView alloc] init]; + NSTableHeaderView *header = [[[NSTableHeaderView alloc] init] autorelease]; [cont setHeaderView:header]; [cont setTarget:cont]; [cont setDoubleAction:@selector(doubleClicked:)]; @@ -6081,7 +6080,7 @@ lastadd = [cont lastAddPoint]; } - browsercell = [[DWImageAndTextCell alloc] init]; + browsercell = [[[DWImageAndTextCell alloc] init] autorelease]; [browsercell setImage:icon]; [browsercell setStringValue:[ NSString stringWithUTF8String:filename ]]; [cont editCell:browsercell at:(row+lastadd) and:0]; @@ -6757,7 +6756,7 @@ [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] flipped:YES]]; - [[NSDictionary alloc] initWithObjectsAndKeys:image, NSGraphicsContextDestinationAttributeName, nil]; + [[[NSDictionary alloc] initWithObjectsAndKeys:image, NSGraphicsContextDestinationAttributeName, nil] autorelease]; // make a new transform: NSAffineTransform *t = [NSAffineTransform transform]; @@ -6792,11 +6791,11 @@ if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) return NULL; NSString *nstr = [ NSString stringWithUTF8String:filename ]; - NSImage *tmpimage = [[NSImage alloc] initWithContentsOfFile:nstr]; + NSImage *tmpimage = [[[NSImage alloc] initWithContentsOfFile:nstr] autorelease]; if(!tmpimage && ext) { nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]]; - tmpimage = [[NSImage alloc] initWithContentsOfFile:nstr]; + tmpimage = [[[NSImage alloc] initWithContentsOfFile:nstr] autorelease]; } if(!tmpimage) return NULL; @@ -6837,7 +6836,7 @@ if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) return NULL; NSData *thisdata = [NSData dataWithBytes:data length:len]; - NSImage *tmpimage = [[NSImage alloc] initWithData:thisdata]; + NSImage *tmpimage = [[[NSImage alloc] initWithData:thisdata] autorelease]; if(!tmpimage) return NULL; NSSize size = [tmpimage size]; @@ -8486,7 +8485,7 @@ if(filename) { - bitmap = [[NSImage alloc] initWithContentsOfFile:[ NSString stringWithUTF8String:filename ]]; + bitmap = [[[NSImage alloc] initWithContentsOfFile:[ NSString stringWithUTF8String:filename ]] autorelease]; } else if(resid > 0 && resid < 65536) {