Skip to content

Commit b84752c

Browse files
author
andypotion
committed
Fix memory leaks
git-svn-id: http://shortcutrecorder.googlecode.com/svn/trunk@25 95fa3068-9819-0410-9c96-7759cbfcbc6e
1 parent 05057da commit b84752c

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

Source/SRCommon.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ unsigned int SRCocoaToCarbonFlags( unsigned int cocoaFlags )
173173
UInt32 deadKeyState;
174174
OSStatus err = noErr;
175175
CFLocaleRef locale = CFLocaleCopyCurrent();
176+
[(id)locale autorelease]; // Autorelease here so that it gets released no matter what
176177

177178
CFMutableStringRef resultString;
178179

@@ -241,16 +242,14 @@ unsigned int SRCocoaToCarbonFlags( unsigned int cocoaFlags )
241242
err = UCKeyTranslate( uchrData, (UInt16)keyCode, kUCKeyActionDisplay, modifiers, LMGetKbdType(), kUCKeyTranslateNoDeadKeysBit, &deadKeyState, maxStringLength, &actualStringLength, unicodeString );
242243
CFStringRef temp = CFStringCreateWithCharacters(kCFAllocatorDefault, unicodeString, 1);
243244
resultString = CFStringCreateMutableCopy(kCFAllocatorDefault, 0,temp);
244-
if(temp)
245+
if (temp)
245246
CFRelease(temp);
246247
}
247248
CFStringCapitalize(resultString, locale);
248-
CFRelease(locale);
249249

250250
PUDNSLog(@"character: -%@-", (NSString *)resultString);
251251

252252
return (NSString *)resultString;
253-
254253
}
255254

256255
#pragma mark Animation Easing
@@ -367,6 +366,7 @@ + (NSImage *)supportingImageWithName:(NSString *)name {
367366
// NSLog(@"created customImageRep: %@", customImageRep);
368367
NSImage *returnImage = [[NSImage alloc] initWithSize:size];
369368
[returnImage addRepresentation:customImageRep];
369+
[customImageRep release];
370370
[returnImage setScalesWhenResized:YES];
371371
[SRSharedImageCache setObject:returnImage forKey:name];
372372

@@ -383,6 +383,7 @@ + (NSImage *)supportingImageWithName:(NSString *)name {
383383
// NSLog(@"created customImageRepQDRPL: %@", customImageRepQDRPL);
384384
NSImage *returnImageQDRPL = [[NSImage alloc] initWithSize:sizeQDRPL];
385385
[returnImageQDRPL addRepresentation:customImageRepQDRPL];
386+
[customImageRepQDRPL release];
386387
[returnImageQDRPL setScalesWhenResized:YES];
387388
[returnImageQDRPL setFlipped:YES];
388389
NSData *tiffQDRPL = [returnImageQDRPL TIFFRepresentation];
@@ -439,6 +440,9 @@ + (void)_drawSRSnapback:(id)anNSCustomImageRep {
439440

440441
[bp fill];
441442

443+
[bp release];
444+
[flip release];
445+
[sh release];
442446
}
443447

444448
+ (NSValue *)_sizeSRRemoveShortcut {

Source/SRKeyCodeTransformer.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ - (id) transformedValue:(id)value
182182
length,
183183
&realLength,
184184
chars);
185+
186+
if ( err != noErr ) return nil;
185187

186188
NSString *keyString = [[NSString stringWithCharacters:chars length:1] uppercaseString];
187189

Source/SRRecorderCell.m

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,13 @@ - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
377377
isVaguelyRecording = YES;
378378
}
379379

380-
// NSAffineTransform *transitionMovement = [[NSAffineTransform alloc] init];
381-
NSAffineTransform *viewportMovement = [[NSAffineTransform alloc] init];
382-
CTGradient *currRecordingGradient = [recordingGradient gradientWithAlphaComponent:0.3];
380+
// NSAffineTransform *transitionMovement = [NSAffineTransform transform];
381+
NSAffineTransform *viewportMovement = [NSAffineTransform transform];
383382
// Draw gradient when in recording mode
384383
if (isVaguelyRecording)
385384
{
386385
if (isAnimatingNow) {
387386
// [transitionMovement translateXBy:(isAnimatingTowardsRecording ? -(NSWidth(cellFrame)*(1.0-xanim)) : +(NSWidth(cellFrame)*xanim)) yBy:0.0];
388-
currRecordingGradient = [currRecordingGradient gradientWithAlphaComponent:alphaRecording];
389387
if (SRAnimationAxisIsY) {
390388
// [viewportMovement translateXBy:0.0 yBy:(isAnimatingTowardsRecording ? -(NSHeight(cellFrame)*(xanim)) : -(NSHeight(cellFrame)*(1.0-xanim)))];
391389
[viewportMovement translateXBy:0.0 yBy:(isAnimatingTowardsRecording ? NSHeight(cellFrame)*(xanim) : NSHeight(cellFrame)*(1.0-xanim))];
@@ -413,11 +411,6 @@ - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
413411

414412
// if (isVaguelyRecording)
415413
{
416-
roundedRect = [viewportMovement transformBezierPath:[NSBezierPath bezierPathWithSRCRoundRectInRect:SRAnimationOffsetRect(cellFrame,cellFrame) radius:NSHeight(cellFrame)/2.0]];
417-
418-
// Fill background with gradient
419-
// [currRecordingGradient fillRect:cellFrame angle:90.0];
420-
421414
NSRect snapBackRect = SRAnimationOffsetRect([self _snapbackRectForFrame: cellFrame],cellFrame);
422415
// NSLog(@"snapbackrect: %@; offset: %@", NSStringFromRect([self _snapbackRectForFrame: cellFrame]), NSStringFromRect(snapBackRect));
423416
NSPoint correctedSnapBackOrigin = [viewportMovement transformPoint:snapBackRect.origin];
@@ -647,7 +640,7 @@ - (void)mouseExited:(NSEvent*)theEvent
647640
- (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(SRRecorderControl *)controlView untilMouseUp:(BOOL)flag
648641
{
649642
NSEvent *currentEvent = theEvent;
650-
NSPoint mouseLocation = [controlView convertPoint:[currentEvent locationInWindow] fromView:nil];
643+
NSPoint mouseLocation;
651644

652645
NSRect trackingRect = (isRecording ? [self _snapbackRectForFrame: cellFrame] : [self _removeButtonRectForFrame: cellFrame]);
653646
NSRect leftRect = cellFrame;
@@ -1192,13 +1185,11 @@ - (void)_saveKeyCombo
11921185

11931186
if (hasKeyChars) {
11941187

1195-
NSMutableDictionary *mutableDefaultsValue = [defaultsValue mutableCopy];
1188+
NSMutableDictionary *mutableDefaultsValue = [[defaultsValue mutableCopy] autorelease];
11961189
[mutableDefaultsValue setObject:keyChars forKey:@"keyChars"];
11971190
[mutableDefaultsValue setObject:keyCharsIgnoringModifiers forKey:@"keyCharsIgnoringModifiers"];
11981191

1199-
defaultsValue = [mutableDefaultsValue copy];
1200-
[mutableDefaultsValue release];
1201-
1192+
defaultsValue = mutableDefaultsValue;
12021193
}
12031194

12041195
[values setValue:defaultsValue forKey:[self _defaultsKeyForAutosaveName: defaultsKey]];

Source/SRValidator.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ - (id) delegate
242242

243243
- (void) setDelegate: (id) theDelegate
244244
{
245-
delegate = [theDelegate retain];
245+
delegate = theDelegate; // Standard delegate pattern does not retain the delegate
246246
}
247247

248248
@end

0 commit comments

Comments
 (0)