From patchwork Tue Apr 4 18:24:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 13200820 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE415C77B6C for ; Tue, 4 Apr 2023 18:25:22 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.518117.804320 (Exim 4.92) (envelope-from ) id 1pjlL5-0003Do-EN; Tue, 04 Apr 2023 18:25:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 518117.804320; Tue, 04 Apr 2023 18:25:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pjlL5-0003Dh-BE; Tue, 04 Apr 2023 18:25:03 +0000 Received: by outflank-mailman (input) for mailman id 518117; Tue, 04 Apr 2023 18:25:02 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pjlL4-0003Db-DB for xen-devel@lists.xenproject.org; Tue, 04 Apr 2023 18:25:02 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 02b171ab-d316-11ed-85db-49a42c6b2330; Tue, 04 Apr 2023 20:25:01 +0200 (CEST) Received: from [2001:8b0:10b:5:99d7:d5a0:55b7:41c3] (helo=u3832b3a9db3152.ant.amazon.com) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pjlL2-00Fbl8-3s; Tue, 04 Apr 2023 18:25:00 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 02b171ab-d316-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=MIME-Version:Content-Type:Date:Cc:To: From:Subject:Message-ID:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:In-Reply-To:References; bh=480JJEkRxs3cmNNvJ6vGQyvJ1jJTqswEUwkTvI30tHc=; b=onf3GHa5oA8L0Q8WHPctBlPRUW zHbocjgALQoABlp3ZuxwkP093PFoR8fNhfXGq7VdpaL5Jqn70+CPmKTlOK8ypnn2CK7y4Wt6WY/+s Qv4L+OTeCABVyU9PvgyFa02QfsH0g6IFbUszb+3kih8UgsPVsrxkjXb4gX7T1EE3QVeU2+nc3Qn8i 8GxXREN4h3+7tm7jBzGEGDKqjpEpd2W6OOhMROVwD6Ey5HTd+KtCWjzcM33o0XSGfYSr2Qwrz2iDz ZB4GbV+pPvGdBodDDwbV1QSX3LjjC4VicQIXWXPeumJDV6w+qmydTovyCnDE3NDDODkkkb7nrKq20 /e0Vmrng==; Message-ID: Subject: [PATCH] hw/xen: Fix memory leak in libxenstore_open() for Xen From: David Woodhouse To: qemu-devel Cc: xen-devel , Paul Durrant , Anthony Perard , Stefano Stabellini , Peter Maydell Date: Tue, 04 Apr 2023 19:24:59 +0100 User-Agent: Evolution 3.44.4-0ubuntu1 MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html From: David Woodhouse There was a superfluous allocation of the XS handle, leading to it being leaked on both the error path and the success path (where it gets allocated again). Spotted by Coverity (CID 1508098). Fixes: ba2a92db1ff6 ("hw/xen: Add xenstore operations to allow redirection to internal emulation") Suggested-by: Peter Maydell Signed-off-by: David Woodhouse Reviewed-by: Peter Maydell --- hw/xen/xen-operations.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/xen/xen-operations.c b/hw/xen/xen-operations.c index 4b78fbf4bd..3d213d28df 100644 --- a/hw/xen/xen-operations.c +++ b/hw/xen/xen-operations.c @@ -287,7 +287,7 @@ static void watch_event(void *opaque) static struct qemu_xs_handle *libxenstore_open(void) { struct xs_handle *xsh = xs_open(0); - struct qemu_xs_handle *h = g_new0(struct qemu_xs_handle, 1); + struct qemu_xs_handle *h; if (!xsh) { return NULL;