From patchwork Fri Dec 14 14:42:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 153862 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2155190ljp; Fri, 14 Dec 2018 06:45:32 -0800 (PST) X-Google-Smtp-Source: AFSGD/XbvKpNNq66djxepGkkQJ3KJqIW1M7L0ZP9lAP58dsaVXcyIaum3oR9KaPUnrmhspFNAkfB X-Received: by 2002:a0c:e189:: with SMTP id p9mr3021799qvl.68.1544798732063; Fri, 14 Dec 2018 06:45:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544798732; cv=none; d=google.com; s=arc-20160816; b=CitVCDBs/AybIOL3zAC+Pus3nHKSDYfGdTb2INC4iH2jaOdUVZu6am2jfOTsqs5WZw 2kT6enCcfYoV/FQJYRepyhmUxpi5thNdkvKGQghF89C9uV28jO5ovG8abv5hF7ylHR6n jVzHkhnrUDAC+b0mgozWdRqbAoulahTrcAh0n9mIN23Z9UdhzmDuQirAqVDV3YlhnM4f +cxzc81qWep+UZA9L5nNOk9t+S+3krYvcwuWSb8XSGig6zxqKg8NqTyuRIIL3mwwjdNe k+oSd2MJHpy4hHaP5B4mhpdAqLADMjcKMWbFwAlQNnwP8xN0VxZIw3MPYZWCVLLwMias l7ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=lzxn6H0KV9fGw+tJYdNAKNL2ruLWOFeL0rES4z8XhzI=; b=itdQw8oMcFEDjVkmLQ4Mo2xM3n1krJ+1dHyJBmbp5+Z1atfawdA/Q9zkEin+nPeZa+ kptWnqaaJtSql0LI1C7HwHTFgOO1F4Qfrkgl/kLQByFy9hXCzdVfut278yOnD7TFWt/q ziqKK/pZCGiuPfi9wwlVcU39TQU8vUQpqj6jFihJk/b4TYWCkxcSuVkOvwRPnsVOgjsq OUn0u1nMzF0rFYtJdZlHFxwcGko4CIufDBd5BSr/e5qa+pxhEbTq3jQnYWxclZ7+2HxA eJLDywfHXhb+aTEwS8ipTLeH575j6i+JzzIH3c+fZucXGHvoNhPQgwGRbTp76zBh3LDy Nvfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RmUxKI4i; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id t5si2712715qvj.105.2018.12.14.06.45.31 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 14 Dec 2018 06:45:32 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RmUxKI4i; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33893 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXoiZ-0003L6-IJ for patch@linaro.org; Fri, 14 Dec 2018 09:45:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38495) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXofr-0000EX-UK for qemu-devel@nongnu.org; Fri, 14 Dec 2018 09:42:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gXofq-0004Y5-Tr for qemu-devel@nongnu.org; Fri, 14 Dec 2018 09:42:43 -0500 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]:45417) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gXofq-0004WR-Kf for qemu-devel@nongnu.org; Fri, 14 Dec 2018 09:42:42 -0500 Received: by mail-wr1-x430.google.com with SMTP id t6so5496390wrr.12 for ; Fri, 14 Dec 2018 06:42:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=lzxn6H0KV9fGw+tJYdNAKNL2ruLWOFeL0rES4z8XhzI=; b=RmUxKI4iQz20HsjTOMve/vGYdS9WMeCUmv+1B6PvhUooojSKau8xShb+y7Gor7u+0n mVg+tUwDafLtfbRxPM+f28cGBKbqtmseHPPP9ZmUnWT+JfHzij1sbfAtZU9mkYIsXliG pN0ljLKt/AyUH+q/cLvR/v1fvNc5iW4a1UYPU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lzxn6H0KV9fGw+tJYdNAKNL2ruLWOFeL0rES4z8XhzI=; b=TWOFKLMPR9nwet6F2Aqptd1C96weiZU3nevBO8D5wnZvWc2oies+rXl2WbZj4wjcoG 6xl5q8pDNramVdFAQSGfWGvSr6bS6JztMVYgXCaV/VUwY0WXB8+7VxCD/kWVckj3JgqT UVHYhsIAYLdNT/2irT2nW61qqUBKdyt0f0uf3sOJF+jzSuLyc7KyRUCua4AFOhbVT5jm y/2JGy2wD87xbzAtQAZqAcEbIUJ0i820It0YO7RS1sAoLOG3Mxax//NVAIBgl2a2XV+C IzwdiI+ftlDn+sQIhxb/fH79sUyeCumoqMAsZa1Yj4TTeb/3YT8RAe27Tdq9MmK/n2pa LLeA== X-Gm-Message-State: AA+aEWYNyTlA6ZFwDOgyJiIFps9yv7gx/02LAzrBi59VFtbz3UlkM0yP ak3Pmf35e+R+2I5kqWkqKK0IebKBqsg= X-Received: by 2002:adf:a1d2:: with SMTP id v18mr2738193wrv.87.1544798561160; Fri, 14 Dec 2018 06:42:41 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id m6sm3263204wrv.24.2018.12.14.06.42.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Dec 2018 06:42:40 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 14 Dec 2018 14:42:13 +0000 Message-Id: <20181214144214.1260-22-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181214144214.1260-1-peter.maydell@linaro.org> References: <20181214144214.1260-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::430 Subject: [Qemu-devel] [PULL 21/22] target/arm: Create timers in realize, not init X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The timer_new() function allocates memory; this means that if we call it in the CPU's init method we would need to provide an instance_finalize method to free it. Defer the timer creation to the realize function instead. This fixes a memory leak spotted by clang LeakSanitizer when a CPU object is created for introspection. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20181204132952.2601-6-peter.maydell@linaro.org --- target/arm/cpu.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) -- 2.19.2 diff --git a/target/arm/cpu.c b/target/arm/cpu.c index b84a6c0e678..0e7138c9bfb 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -679,14 +679,6 @@ static void arm_cpu_initfn(Object *obj) qdev_init_gpio_in(DEVICE(cpu), arm_cpu_set_irq, 4); } - cpu->gt_timer[GTIMER_PHYS] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE, - arm_gt_ptimer_cb, cpu); - cpu->gt_timer[GTIMER_VIRT] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE, - arm_gt_vtimer_cb, cpu); - cpu->gt_timer[GTIMER_HYP] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE, - arm_gt_htimer_cb, cpu); - cpu->gt_timer[GTIMER_SEC] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE, - arm_gt_stimer_cb, cpu); qdev_init_gpio_out(DEVICE(cpu), cpu->gt_timer_outputs, ARRAY_SIZE(cpu->gt_timer_outputs)); @@ -882,6 +874,15 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) return; } } + + cpu->gt_timer[GTIMER_PHYS] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE, + arm_gt_ptimer_cb, cpu); + cpu->gt_timer[GTIMER_VIRT] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE, + arm_gt_vtimer_cb, cpu); + cpu->gt_timer[GTIMER_HYP] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE, + arm_gt_htimer_cb, cpu); + cpu->gt_timer[GTIMER_SEC] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE, + arm_gt_stimer_cb, cpu); #endif cpu_exec_realizefn(cs, &local_err);