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

Felix Paul Kühne git at videolan.org
Mon Apr 25 14:09:43 CEST 2011


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Mon Apr 25 14:09:39 2011 +0200| [86027501c6ad6ff3684c9918485e5539d93ae036] | committer: Felix Paul Kühne

macosx: fixed a leak in the Apple Remote class

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=86027501c6ad6ff3684c9918485e5539d93ae036
---

 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 12e8ca3..b1cb764 100644
--- a/modules/gui/macosx/AppleRemote.h
+++ b/modules/gui/macosx/AppleRemote.h
@@ -108,6 +108,7 @@ The class is not thread safe
 
     IBOutlet id delegate;
 }
++ (AppleRemote *)sharedInstance;
 
 - (int) remoteId;
 
diff --git a/modules/gui/macosx/AppleRemote.m b/modules/gui/macosx/AppleRemote.m
index cfe96c2..3fa3d45 100644
--- a/modules/gui/macosx/AppleRemote.m
+++ b/modules/gui/macosx/AppleRemote.m
@@ -65,8 +65,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;
@@ -124,13 +135,13 @@ const NSTimeInterval HOLD_RECOGNITION_TIME_INTERVAL=0.4;
             [cookieToButtonMapping setObject:[NSNumber numberWithInt:k2009RemoteButtonPlay]       forKey:@"33_21_20_8_2_33_21_20_8_2_"];
             [cookieToButtonMapping setObject:[NSNumber numberWithInt:k2009RemoteButtonFullscreen] forKey:@"33_21_20_3_2_33_21_20_3_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 8c56c8c..aa3ec62 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