From patchwork Mon Mar 25 22:31:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 231004 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E247B2C009B for ; Tue, 26 Mar 2013 09:32:11 +1100 (EST) Received: from localhost ([::1]:44583 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKFw2-0006hf-3h for incoming@patchwork.ozlabs.org; Mon, 25 Mar 2013 18:32:10 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48425) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKFvZ-0006gC-0U for qemu-devel@nongnu.org; Mon, 25 Mar 2013 18:31:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKFvW-00083t-FF for qemu-devel@nongnu.org; Mon, 25 Mar 2013 18:31:40 -0400 Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa ([2001:8b0:1d0::1]:33202 helo=mnementh.archaic.org.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKFvW-00083N-8f for qemu-devel@nongnu.org; Mon, 25 Mar 2013 18:31:38 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1UKFvS-00024W-W4; Mon, 25 Mar 2013 22:31:34 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 25 Mar 2013 22:31:31 +0000 Message-Id: <1364250694-7939-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1364250694-7939-1-git-send-email-peter.maydell@linaro.org> References: <1364250694-7939-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= , patches@linaro.org Subject: [Qemu-devel] [PATCH v2 1/4] ui/cocoa.m: Fix leaks of NSScreen and NSConcreteMapTable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On MacOSX 10.8 QEMU provokes system log messages: 11/03/2013 17:03:29.998 qemu-system-arm[42586]: objc[42586]: Object 0x7ffbf9c2f3b0 of class NSScreen autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug 11/03/2013 17:03:29.999 qemu-system-arm[42586]: objc[42586]: Object 0x7ffbf9c3a010 of class NSConcreteMapTable autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug This is because we call back into Cocoa from threads other than the UI thread (specifically from the CPU thread). Since we created these threads via the POSIX API rather than NSThread, they don't have automatically created autorelease pools. Guard all the functions where QEMU can call back into the Cocoa UI code with autorelease pools so that we don't leak any Cocoa objects. Signed-off-by: Peter Maydell --- ui/cocoa.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 048cc97..e9120e4 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -960,6 +960,8 @@ int main (int argc, const char * argv[]) { static void cocoa_update(DisplayChangeListener *dcl, int x, int y, int w, int h) { + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + COCOA_DEBUG("qemu_cocoa: cocoa_update\n"); NSRect rect; @@ -973,18 +975,24 @@ static void cocoa_update(DisplayChangeListener *dcl, h * [cocoaView cdy]); } [cocoaView setNeedsDisplayInRect:rect]; + + [pool release]; } static void cocoa_switch(DisplayChangeListener *dcl, DisplaySurface *surface) { - COCOA_DEBUG("qemu_cocoa: cocoa_resize\n"); + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + COCOA_DEBUG("qemu_cocoa: cocoa_switch\n"); [cocoaView switchSurface:surface]; + [pool release]; } static void cocoa_refresh(DisplayChangeListener *dcl) { + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + COCOA_DEBUG("qemu_cocoa: cocoa_refresh\n"); if (kbd_mouse_is_absolute()) { @@ -1007,6 +1015,7 @@ static void cocoa_refresh(DisplayChangeListener *dcl) } } while(event != nil); vga_hw_update(); + [pool release]; } static void cocoa_cleanup(void)