[vlc-commits] macosx: fixed a leak in the Apple Remote class

Felix Paul Kühne git at videolan.org
Tue Apr 19 23:35:01 CEST 2011


vlc/vlc-1.1 | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Tue Apr 19 23:33:53 2011 +0200| [28656c6c1de5a6a826628ac3ef4b81307ff50022] | committer: Felix Paul Kühne

macosx: fixed a leak in the Apple Remote class

> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.1.git/?a=commit;h=28656c6c1de5a6a826628ac3ef4b81307ff50022
---

 modules/gui/macosx/AppleRemote.h |    1 +
 modules/gui/macosx/AppleRemote.m |   25 ++++++++++++++++++-------
 modules/gui/macosx/prefs.m       |    3 ++-
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/modules/gui/macosx/AppleRemote.h b/modules/gui/macosx/AppleRemote.h
index fbc9674..8477778 100644
--- a/modules/gui/macosx/AppleRemote.h
+++ b/modules/gui/macosx/AppleRemote.h
@@ -110,6 +110,7 @@ typedef enum AppleRemoteEventIdentifier AppleRemoteEventIdentifier;
     
     IBOutlet id delegate;
 }
++ (AppleRemote *)sharedInstance;
 
 - (int) remoteId;
 
diff --git a/modules/gui/macosx/AppleRemote.m b/modules/gui/macosx/AppleRemote.m
index 418cc08..3099e84 100644
--- a/modules/gui/macosx/AppleRemote.m
+++ b/modules/gui/macosx/AppleRemote.m
@@ -66,8 +66,19 @@ const NSTimeInterval HOLD_RECOGNITION_TIME_INTERVAL=0.4;
 
 #pragma public interface
 
-- (id) init {
-    if(( self = [super init])) {
+static AppleRemote *_o_sharedInstance = nil;
+
++ (AppleRemote *)sharedInstance
+{
+    return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
+}
+
+- (id)init
+{
+    if (_o_sharedInstance) {
+        [self dealloc];
+    } else {
+        _o_sharedInstance = [super init];
         openInExclusiveMode = YES;
         queue = NULL;
         hidDeviceInterface = NULL;
@@ -130,13 +141,13 @@ const NSTimeInterval HOLD_RECOGNITION_TIME_INTERVAL=0.4;
             [cookieToButtonMapping setObject:[NSNumber numberWithInt:k2009RemoteButtonFullscreen] forKey:@"33_21_20_3_2_33_21_20_3_2_"];
             switchCookie = @"42_33_23_21_20_2_33_23_21_20_2_";
         }
+
+        /* defaults */
+        [self setSimulatesPlusMinusHold: YES];
+        maxClickTimeDifference = DEFAULT_MAXIMUM_CLICK_TIME_DIFFERENCE;
     }
     
-    /* defaults */
-    [self setSimulatesPlusMinusHold: YES];
-    maxClickTimeDifference = DEFAULT_MAXIMUM_CLICK_TIME_DIFFERENCE;
-    
-    return self;
+    return _o_sharedInstance;
 }
 
 - (void) dealloc {
diff --git a/modules/gui/macosx/prefs.m b/modules/gui/macosx/prefs.m
index 8cee063..3c76b5d 100644
--- a/modules/gui/macosx/prefs.m
+++ b/modules/gui/macosx/prefs.m
@@ -516,8 +516,9 @@ static VLCPrefs *_o_sharedMainInstance = nil;
 
 - (id)initWithConfigItem: (module_config_t *) configItem
 {
-    NSString * name = [[[VLCMain sharedInstance] localizedString:configItem->psz_name] autorelease];
+    NSString * name = [[VLCMain sharedInstance] localizedString:configItem->psz_name];
     self = [super initWithName:name];
+    [name release];
     if( self != nil )
     {
         _configItem = configItem;



More information about the vlc-commits mailing list