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: 15635 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 13E7C23E39 for ; Mon, 25 Mar 2013 22:31:40 +0000 (UTC) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by fiordland.canonical.com (Postfix) with ESMTP id BD666A195EC for ; Mon, 25 Mar 2013 22:31:39 +0000 (UTC) Received: by mail-ve0-f175.google.com with SMTP id pb11so2300797veb.20 for ; Mon, 25 Mar 2013 15:31:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=yNExGuDfqh90jBgVJ/jlbBLs6Kzu78wBpc6CNkjRXGs=; b=dahF3sGL86pJ99JO4Xjr5Ab5c79zLFJ8192iFyFToRRtBPqlFpGGbKqRXz8Yq28YaN +ceS3W6pmzWfzxqUijsAdcM6r9EUBRz2i/ZTG9HLxIlUjFNxs5ymTH2NW3HbKbNt5vv0 0ZzrFNll2fkM4GfEXAMzzIaczRIR1e9HRt30j61MmMjwZw1n1XTzwiHXUrt7hhCqDaYv cXWGZSzoHGhqy+DyGFl+2Xm0/C1Z39sQFnOjDuP7sFQat8GxpZQny8hVSAzraYwkOpgf St2c7P/A6zUILSCpUCmEYrEkq5vtZwLEvzfeYd8R5MeTpInMHTsihpVqbwFedLVpmah9 ePRQ== X-Received: by 10.52.76.103 with SMTP id j7mr15522417vdw.90.1364250699082; Mon, 25 Mar 2013 15:31:39 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.59.4.204 with SMTP id cg12csp45843ved; Mon, 25 Mar 2013 15:31:38 -0700 (PDT) X-Received: by 10.194.158.161 with SMTP id wv1mr21026059wjb.38.1364250697164; Mon, 25 Mar 2013 15:31:37 -0700 (PDT) Received: from mnementh.archaic.org.uk (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]) by mx.google.com with ESMTPS id en17si1467814wjd.163.2013.03.25.15.31.36 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 25 Mar 2013 15:31:37 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk 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 Cc: patches@linaro.org, =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [PATCH v2 1/4] ui/cocoa.m: Fix leaks of NSScreen and NSConcreteMapTable 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-Gm-Message-State: ALoCoQnUefNwDs2S3X51ogPIdyq4LOl0HI/DTlhgeSjmCYt5vEbDZWBiAdU0LLCyc7UM7ziUuyP9 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)