From 70a20d4822cf8fec4a1c2fd6b2760fafcc20a36f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Felix=20Paul=20K=C3=BChne?= <fkuehne@videolan.org>
Date: Thu, 2 May 2013 15:10:04 +0100
Subject: [PATCH] macosx: fix longstanding ~30KB memory leak in the AppleRemote
 wrapper

---
 modules/gui/macosx/AppleRemote.m | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/modules/gui/macosx/AppleRemote.m b/modules/gui/macosx/AppleRemote.m
index 1a8e113d5334..b526a60f7ca5 100644
--- a/modules/gui/macosx/AppleRemote.m
+++ b/modules/gui/macosx/AppleRemote.m
@@ -544,7 +544,7 @@ static void QueueCallbackFunction(void* target,  IOReturn result, void* refcon,
     long                    usage;
     long                    usagePage;
     id                      object;
-    NSArray*                elements = nil;
+    NSArray*                elements;
     NSDictionary*           element;
     IOReturn success;
 
@@ -557,8 +557,6 @@ static void QueueCallbackFunction(void* target,  IOReturn result, void* refcon,
     success = (*handle)->copyMatchingElements(handle, NULL, (CFArrayRef*)&elements);
 
     if (success == kIOReturnSuccess) {
-
-        [elements autorelease];
         /*
         cookies = calloc(NUMBER_OF_APPLE_REMOTE_ACTIONS, sizeof(IOHIDElementCookie));
         memset(cookies, 0, sizeof(IOHIDElementCookie) * NUMBER_OF_APPLE_REMOTE_ACTIONS);
@@ -588,7 +586,10 @@ static void QueueCallbackFunction(void* target,  IOReturn result, void* refcon,
         }
         _allCookies = [[NSArray alloc] initWithArray: mutableAllCookies];
         [mutableAllCookies release];
+        [elements release];
     } else {
+        if (elements)
+            [elements release];
         return NO;
     }
 
-- 
GitLab