From patchwork Wed Apr 12 10:04:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Klaus Jensen X-Patchwork-Id: 1768015 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=irrelevant.dk header.i=@irrelevant.dk header.a=rsa-sha256 header.s=fm2 header.b=pStjvbZm; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=gy+HKHmF; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PxJHh63szz1yZk for ; Wed, 12 Apr 2023 20:05:35 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmXLP-0004Zn-5H; Wed, 12 Apr 2023 06:04:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmXLN-0004Ys-4N; Wed, 12 Apr 2023 06:04:49 -0400 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmXLL-0005O0-F3; Wed, 12 Apr 2023 06:04:48 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 6169D320099C; Wed, 12 Apr 2023 06:04:45 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 12 Apr 2023 06:04:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to; s=fm2; t=1681293885; x=1681380285; bh=tphiNIweYkcl0zw7aRQKO+uVS BQX157Xly3CeKDLTkI=; b=pStjvbZm8bN6oSHk1w0xcnjJZce7pfcJNQe4MlbPm JuqMn/ZBrfvuBtwcHeZtdQXssvViUUC0Hr2DeHhc9uZdrGBBujd0uRVL63I3fIfV qaGS69VVOKkHjIzOftTdXIWv2IAQRWPxFujv8zkLvKjlqfuPovZxKvEG95iuxg+d TGgEhcgt1+ryohHI7l/fNhIvj8yyLt1B2wvnYb4T5PYTZ0S9vFogi9Y06j1ESU3m ZZ8kyMcFmMjW0LQm1u2Xux6H5vBZh3ZoQvLiFtK6KMAalO619Z0B8D8nmUZz96No k0n6E4mTnVT8jjHkFBmxo4cXUcp+5yX1wRYw3vxYfDdfg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1681293885; x=1681380285; bh=tphiNIweYkcl0zw7aRQKO+uVSBQX157Xly3 CeKDLTkI=; b=gy+HKHmF+Bq2vU5895eO0m109Gjnb6cGAYtXY7QIMVIzxZBXRUY WHMATxTFOFrFN3ZeuGZzpzELXRIVodrqoaJWRmY7qXbK8JQPjODaB6WuSQA7LiBL Kc0vd2wdqm993dRbvy/R5lGUBBOtjlUuCasZh7llG3qRooV3TxRx5lSVBHuAIpo0 IMZodKdzBL/iC/zdWL76T0RCbXQ/72EJVTVVrm/MJ+HWsXoq+nRnjmH3Joilx5hg Vx5Zg7bN+1xNKytEdtmAJwVcDK7bwN0srWawBh7MyV9wB6/VZ5SxX9ElLtnjP9Cr BWmv1SFfMfsOO9mceeRv39vMvW7Nuumw5lw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdekiedgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhggtgfgsehtkeertdertdejnecuhfhrohhmpefmlhgr uhhsucflvghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrg htthgvrhhnpeefvedtueetueduffevgffgtdeftdeuleffhfeigeffkeegfeejfeffteej iefhvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hithhssehirhhrvghlvghvrghnthdrughk X-ME-Proxy: Feedback-ID: idc91472f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 12 Apr 2023 06:04:43 -0400 (EDT) From: Klaus Jensen To: qemu-devel@nongnu.org, Peter Maydell Cc: Keith Busch , Klaus Jensen , qemu-block@nongnu.org, Klaus Jensen , =?utf-8?q?Phili?= =?utf-8?q?ppe_Mathieu-Daud=C3=A9?= Subject: [PULL for-8.0 2/2] hw/nvme: fix memory leak in nvme_dsm Date: Wed, 12 Apr 2023 12:04:36 +0200 Message-Id: <20230412100436.94038-3-its@irrelevant.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412100436.94038-1-its@irrelevant.dk> References: <20230412100436.94038-1-its@irrelevant.dk> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=919; i=k.jensen@samsung.com; h=from:subject; bh=dg013DH4rtfyR99vmVe1/pFSn0W94O6mRsVtwz4hrB4=; b=owJ4nAFtAZL+kA0DAAoBTeGvMW1PDekByyZiAGQ2gjRS/N3diqeTkCG2NeIwS+F48zNIrUeRN MVs2QT1JDv6bIkBMwQAAQoAHRYhBFIoM6p14tzmokdmwE3hrzFtTw3pBQJkNoI0AAoJEE3hrzFt Tw3pKbIH/29GRL5qd3bhOWQs8M5d9bUm42T7pGl7rICO07oATZ1qu08PJKWryvhiWikhV/4keTh dZQ8v390BKbhBMyOifUlt85avAVXsivXFRxMkYQM6RuubW7B7x0GdESfjqfDuvvpY7co9sVuTy8 mQ6Unohb9RlRi7r8LDVW5KxPJr8MmyJkI9i2LG4wy+MutGx33rMXc53lJ2vd56CZ5Q3CAJZHgN8 7n8B4R2mtElpgNBF/hqOP5Y9zo9IsEecem6MaKTIvYVvh8j/qhhi/lBtM25F0GI2Myqa84APFI1 aQJ0gCY7fMXV7E5ZFrCT0VHb+7F5cla/UteDZR7eiCW/nKhmeTPGK6wM X-Developer-Key: i=k.jensen@samsung.com; a=openpgp; fpr=DDCA4D9C9EF931CC3468427263D56FC5E55DA838 Received-SPF: pass client-ip=64.147.123.21; envelope-from=its@irrelevant.dk; helo=wout5-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 From: Klaus Jensen The iocb (and the allocated memory to hold LBA ranges) leaks if reading the LBA ranges fails. Fix this by adding a free and an unref of the iocb. Reported-by: Coverity (CID 1508281) Fixes: d7d1474fd85d ("hw/nvme: reimplement dsm to allow cancellation") Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Klaus Jensen --- hw/nvme/ctrl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 8b7be1420912..ac24eeb5ed5a 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -2619,6 +2619,9 @@ static uint16_t nvme_dsm(NvmeCtrl *n, NvmeRequest *req) status = nvme_h2c(n, (uint8_t *)iocb->range, sizeof(NvmeDsmRange) * nr, req); if (status) { + g_free(iocb->range); + qemu_aio_unref(iocb); + return status; }