From nobody Fri Dec 19 21:50:28 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 174463240067660.93054734598354; Mon, 14 Apr 2025 05:06:40 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2424D151F; Mon, 14 Apr 2025 08:06:40 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8A31A1504; Mon, 14 Apr 2025 08:06:25 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2272C14FA; Mon, 14 Apr 2025 08:06:22 -0400 (EDT) Received: from air.basealt.ru (air.basealt.ru [193.43.8.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 1BC0C14F5 for ; Mon, 14 Apr 2025 08:06:21 -0400 (EDT) Received: from kuznetsovam-nb.office.basealt.ru (unknown [193.43.10.250]) (Authenticated sender: kuznetsovam) by air.basealt.ru (Postfix) with ESMTPSA id 8B8B9233A6; Mon, 14 Apr 2025 15:06:19 +0300 (MSK) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Alexander Kuznetsov To: devel@lists.libvirt.org Subject: [PATCH] nss: Fix memory leak in findLease Date: Mon, 14 Apr 2025 15:06:09 +0300 Message-ID: <20250414120612.23721-1-kuznetsovam@altlinux.org> X-Mailer: git-send-email 2.42.4 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 7Q5D6DG4DIMVL3BQSUQTF533OEI5WY7F X-Message-ID-Hash: 7Q5D6DG4DIMVL3BQSUQTF533OEI5WY7F X-MailFrom: kuznetsovam@altlinux.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: nickel@altlinux.org, egori@altlinux.org X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZM-MESSAGEID: 1744632402658019000 Content-Type: text/plain; charset="utf-8" path is allocated by asprintf() and must be freed later if realloc() fails = or at the end of each while() iteration Move the free() call out of LIBVIRT_NSS_GUEST macro and add another one if realloc() fails Found by Linux Verification Center (linuxtesting.org) with Svace. Reported-by: Dmitry Fedin Signed-off-by: Alexander Kuznetsov --- tools/nss/libvirt_nss.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c index d79a00a1b0..190cc7a3dd 100644 --- a/tools/nss/libvirt_nss.c +++ b/tools/nss/libvirt_nss.c @@ -141,8 +141,11 @@ findLease(const char *name, goto cleanup; =20 tmpLease =3D realloc(leaseFiles, sizeof(char *) * (nleaseFiles= + 1)); - if (!tmpLease) + if (!tmpLease) { + free(path); goto cleanup; + } + leaseFiles =3D tmpLease; leaseFiles[nleaseFiles++] =3D path; #if defined(LIBVIRT_NSS_GUEST) @@ -155,8 +158,8 @@ findLease(const char *name, free(path); goto cleanup; } - free(path); #endif /* LIBVIRT_NSS_GUEST */ + free(path); } =20 errno =3D 0; --=20 2.42.4