From nobody Thu May 16 08:17:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621255975; cv=none; d=zohomail.com; s=zohoarc; b=aO3PVBicff83ew6fYT+oWZT8aBMyYN8yKwnhvJ9vXRS8NViXVUFUtXblGsdfv3n8gP26aCYnBYuga5G9MqDqyXKl+uNesyTt/dRrufYbfO115oLu0iEcMbVjbS5eqajifj9HuamMUkq9xcNDCGOjMfr7iKg0KdxZ3wXLolRQv/8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621255975; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=asKFtylF+5pJVl27qYf0XPlwzqRNgr+enjifUUTyBgE=; b=AEooQ+ygWkV7uMrQcIJay88CYfTK3sKuYSgzO2toQNmSmrL/7g5Qjvxrz/3I/1owkpYNLa/d28HON9b8OaNGWIdF3lzFkB7gGjgxyMdf66TZMGo6016JiGnKfQK65pnZyxWJIBGcN6qfPbQLe04VwOBr99aZWJnptiJVFhRsPFk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1621255975840974.7453120054159; Mon, 17 May 2021 05:52:55 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-133-St85_ohyM_uXFxIXsIbT5g-1; Mon, 17 May 2021 08:52:51 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0347550206; Mon, 17 May 2021 12:52:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B1CF057998; Mon, 17 May 2021 12:52:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 17B9155347; Mon, 17 May 2021 12:52:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14HCqeoL016477 for ; Mon, 17 May 2021 08:52:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id CE2405C582; Mon, 17 May 2021 12:52:40 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 526D35C22B for ; Mon, 17 May 2021 12:52:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621255974; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=asKFtylF+5pJVl27qYf0XPlwzqRNgr+enjifUUTyBgE=; b=YoVAOXmt/giL0g/4eRdOR47T4nHW70b98TIsum1Icm2TebFwv7f8/E5zq+ZXLbR5io41Ti upBitnnEBbyGw+wtrfHoNg3exGIIQtMhwwKJ1K/co6/3vUY0ZyLbHjGatq2Tb0EIOIsceh V0hj8ga46ibkG/Ubpd3fWcWZ9vZxnXo= X-MC-Unique: St85_ohyM_uXFxIXsIbT5g-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] driver: Don't leak saved error in virGetConnectGeneric() Date: Mon, 17 May 2021 14:52:33 +0200 Message-Id: <0f00a93459269b13f82d977d979f584fc4b4a79d.1621255953.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Recently, a new code was added to virGetConnectGeneric() that saves the original error into a variable so that it's not lost in virConnectClose() called under the 'error' label. However, the error saving code uses virSaveLastError() + virSetError() combo which leaks the memory allocated for the error copy. Using virErrorPreserveLast() + virErrorRestore() does the same job without the memleak. Signed-off-by: Michal Privoznik --- src/driver.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/driver.c b/src/driver.c index 227bb56e48..329d493a50 100644 --- a/src/driver.c +++ b/src/driver.c @@ -138,7 +138,7 @@ static virConnectPtr virGetConnectGeneric(virThreadLocal *threadPtr, const char *name) { virConnectPtr conn; - virErrorPtr saved; + virErrorPtr orig_err; =20 if (virConnectCacheInitialize() < 0) return NULL; @@ -178,9 +178,9 @@ virGetConnectGeneric(virThreadLocal *threadPtr, const c= har *name) return conn; =20 error: - saved =3D virSaveLastError(); + virErrorPreserveLast(&orig_err); virConnectClose(conn); - virSetError(saved); + virErrorRestore(&orig_err); return NULL; } =20 --=20 2.26.3