From patchwork Wed Dec 10 00:06:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 862 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765325310; bh=aCS/RvU/N7WOUtfjp8KSk15CWfKsJA1J4NaKla+FoqQ=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=LQoq5pU6jbIajggQtzvd72C6PCvLjE+hmuWSbNtasFNnP0JRV8Zol2kginEABr6fy M11mnCMYOtbXQcZAOnXMrVg/N7yhWlbJ3irQRswIKWAPVYci2iGtSwscCXX0dlpMwW fleJauOnsMNsWNw5mTknktAUBOpUvLpC0CkSNDXOmYFe7svxfHXIpl9E/8fJ4DUWr4 +j/fsZ0gaHbWyWHrJTa4yaCVngx7kWJkh6NyO7HBqoCfugbQ+aNu0YFBSmCrRhLs5E Xm2VQkIT1G4yEZhDOfV5QH+SjsXLcwb7PAKCJK0pLOnzQZKh5BCtS3caJQgCtAKvkF usAVC/KUIF07Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 91B446898C for ; Tue, 9 Dec 2025 17:08:30 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id Nj6fjN2oBoDs for ; Tue, 9 Dec 2025 17:08:30 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765325310; bh=aCS/RvU/N7WOUtfjp8KSk15CWfKsJA1J4NaKla+FoqQ=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=LQoq5pU6jbIajggQtzvd72C6PCvLjE+hmuWSbNtasFNnP0JRV8Zol2kginEABr6fy M11mnCMYOtbXQcZAOnXMrVg/N7yhWlbJ3irQRswIKWAPVYci2iGtSwscCXX0dlpMwW fleJauOnsMNsWNw5mTknktAUBOpUvLpC0CkSNDXOmYFe7svxfHXIpl9E/8fJ4DUWr4 +j/fsZ0gaHbWyWHrJTa4yaCVngx7kWJkh6NyO7HBqoCfugbQ+aNu0YFBSmCrRhLs5E Xm2VQkIT1G4yEZhDOfV5QH+SjsXLcwb7PAKCJK0pLOnzQZKh5BCtS3caJQgCtAKvkF usAVC/KUIF07Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7F5E9689EC for ; Tue, 9 Dec 2025 17:08:30 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765325308; bh=Kj4JJPjsC5axm0vFnQ+tewl/Foh6sxUWWYi7G4hFUM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v0jcG/4fPe/e1xsOw32tMnbqmxjYBLzzUBeglc419T6cyfnw74N0tCh2tN4vJrKAc gmjZhTI1DyeXFF5L63R9nOj+fsvrjPYLZiuOMF2Xaw52laO/3SObR8m838jEkm5Cya 4ybJuaKqWdF1sRwTMKP/Tmfx5+S+jvoWMCGCzV5ipj62fgMP8Bc1g5h0G5xkHaQFat zNtsHhW8Rnp65JXaEDSn3pCZyTIVwD9FpbwYya7bYWOJHcoOyOUhpthZU+C5L/Ca2g qMaQbvHo2qqJ7EUsm2DFaD2AublNCf6TyPsBcsha0LZBTqd7BZGCNscBURZ6uOXjFK TS0UmcRabsILg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 51F8868972; Tue, 9 Dec 2025 17:08:28 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id gZoWLSnEdWIo; Tue, 9 Dec 2025 17:08:28 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765325303; bh=3sPBQgnRXnhgWIbPwyBkWtBpBVbh+ShdrN5by77jaMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cD0yRmVYUN9/A9JhPCQZeID83f+lneZd2v+HGdSHTjI5uDzLy+OPlJWmi+haKc0cN 2QhqrWl6fNV8UzR2j7SEmXKw10dgIYD/XNHs2FHYJCpIfKtMK3QQuhiz3Relce1Nof fc3Kx+G1kM5clGhLFW6ePgydOoHAjmPXOKmk1Eq7zN43XQlGex+YhM7I9+VmMKXD/E ktG7Hg9AtTRI7wctN3Y/IU9XdEkX1OlLMaudLtO2fshPjqw1ab/1l1weyPvSga2HKk pVWljHrV4rUgEqjab+JJmgO/7xbxuWc9Ou4Y/2ktuWBzqClbEwga7yaIVsQyHMYwOn blteuVtOPxP9g== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 8FA9A68A26; Tue, 9 Dec 2025 17:08:23 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 9 Dec 2025 17:06:56 -0700 Message-ID: <20251210000737.180797-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251210000737.180797-1-sjg@u-boot.org> References: <20251210000737.180797-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: KWE5DJX6AB2QPRI4AOMKJDERVPOGNTZL X-Message-ID-Hash: KWE5DJX6AB2QPRI4AOMKJDERVPOGNTZL X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 05/35] mmc: sandbox: Fix memory leak on probe failure List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass If mmc_init() fails, the buffer allocated by calloc() or mapped by os_map_file() is not freed. Free or unmap the buffer before returning the error. Signed-off-by: Simon Glass --- drivers/mmc/sandbox_mmc.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/sandbox_mmc.c b/drivers/mmc/sandbox_mmc.c index a24520f2e78..f49cb4b146a 100644 --- a/drivers/mmc/sandbox_mmc.c +++ b/drivers/mmc/sandbox_mmc.c @@ -190,7 +190,16 @@ static int sandbox_mmc_probe(struct udevice *dev) } } - return mmc_init(&plat->mmc); + ret = mmc_init(&plat->mmc); + if (ret) { + if (plat->fname) + os_unmap(priv->buf, priv->size); + else + free(priv->buf); + return ret; + } + + return 0; } static int sandbox_mmc_remove(struct udevice *dev)