diff --git a/BigLetterView.m b/BigLetterView.m index 1bfc3ee..35023ca 100644 --- a/BigLetterView.m +++ b/BigLetterView.m @@ -11,7 +11,8 @@ -(void)drawStringCenteredIn:(NSRect)r; @implementation BigLetterView -(id)initWithFrame:(NSRect)rect { - if (![super initWithFrame:rect]) return nil; + self = [super initWithFrame:rect]; + if (!self) return nil; [self prepareAttributes]; bgColor = [[NSColor grayColor] retain]; string = [[NSMutableString alloc] init]; @@ -62,7 +63,7 @@ -(BOOL)becomeFirstResponder { return canBecomeFirstResponder; } -(void)setCanBecomeFirstResponder:(BOOL)flag { canBecomeFirstResponder = flag; } -(void)setBGColor:(NSColor*)col { - col = [col retain]; + [col retain]; if (bgColor) [bgColor release]; bgColor = col; [self setNeedsDisplay:YES]; diff --git a/LED.m b/LED.m index bbebf5a..f92565e 100644 --- a/LED.m +++ b/LED.m @@ -32,6 +32,8 @@ @implementation LED -(id)init { self = [super init]; + CFSetRef deviceCFSetRef = NULL; + IOHIDDeviceRef* refs = NULL; // create a IO HID Manager reference IOHIDManagerRef mgr = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); require(mgr, Oops); @@ -46,12 +48,12 @@ -(id)init IOReturn err = IOHIDManagerOpen(mgr, kIOHIDOptionsTypeNone); require_noerr(err, Oops); // and copy out its devices - CFSetRef deviceCFSetRef = IOHIDManagerCopyDevices(mgr); + deviceCFSetRef = IOHIDManagerCopyDevices(mgr); require(deviceCFSetRef, Oops); // how many devices in the set? CFIndex deviceIndex, deviceCount = CFSetGetCount(deviceCFSetRef); // allocate a block of memory to extact the device refs from the set into - IOHIDDeviceRef* refs = malloc(sizeof(IOHIDDeviceRef) * deviceCount); + refs = malloc(sizeof(IOHIDDeviceRef) * deviceCount); require(refs, Oops); // now extract the device refs from the set CFSetGetValues(deviceCFSetRef, (const void**)refs); @@ -91,13 +93,14 @@ -(id)init continue; } next_device: ; - CFRelease(elements); + if (elements) CFRelease(elements); continue; } if (mgr) CFRelease(mgr); [dic release]; - free(refs); Oops: ; + if (deviceCFSetRef) CFRelease(deviceCFSetRef); + if (refs) free(refs); return self; } diff --git a/Morse.m b/Morse.m index 39963a8..52e7736 100644 --- a/Morse.m +++ b/Morse.m @@ -276,7 +276,6 @@ -(id)initWithWPM:(float)wpm -(uint16_t)feed:(double*)duration { - uint16_t chr = MorseNoCharacter; // Put the event in the buffer if (duration) { @@ -292,8 +291,7 @@ -(uint16_t)feed:(double*)duration if (_bufferCount < MorseBufferSize) _bufferCount++; _buffer[where] = *duration; } - chr = [self _recognize]; - return chr; + return [self _recognize]; } -(MorseRecognizerQuality)quality