From nobody Sun Feb 8 15:29:06 2026 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; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1606245685; cv=none; d=zohomail.com; s=zohoarc; b=KgkOv7LK+y2b4fo3B3xErrHafjn1R9H8zv4mpOlLQAMek5xopPnY97+i+ctSK3aFTSZMA0O+EvFt+flk+kFDCsRpTH4WQi8nVbwW/+7ynWOB+61gQbUxP4kJB6SlMRMj95bHohdub3T93cfS3dyXIWS1Ctdf6qaPVG3CDgXKCxA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606245685; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nKKYuapGPCFdQhmkouPYdBlztwppnkqoOSs4G1fYdvM=; b=P+LyDk4R0c7obN83YUHVBBDzibxKBzSukgQC+ST1x2fxmjStCZCF0neOryG89FtQ2I1fOWyrhr3I9sXSjihxe3ILlbhWVhjHp91k66ZqYLhZ1pL4ivIuoPzfWkVMKdettbpzwuzww7GG7O2B//J/60YL1qNeV2TxCrEIl3xaliE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail 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 1606245685397680.7750006693789; Tue, 24 Nov 2020 11:21:25 -0800 (PST) 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-373-RbE4_Z4JMU-qsJN4QGqoAA-1; Tue, 24 Nov 2020 14:21:20 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 67927801AE8; Tue, 24 Nov 2020 19:21:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F7805D71B; Tue, 24 Nov 2020 19:21:12 +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 0B32A1809CA8; Tue, 24 Nov 2020 19:21:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AOJL3qv004089 for ; Tue, 24 Nov 2020 14:21:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2A84D2026D35; Tue, 24 Nov 2020 19:21:03 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 25FDB2026D25 for ; Tue, 24 Nov 2020 19:21:03 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 11EF9811E78 for ; Tue, 24 Nov 2020 19:21:03 +0000 (UTC) Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-412-LwLChbOGO_i8oTMzvMI6hA-1; Tue, 24 Nov 2020 14:21:00 -0500 Received: by mail-qv1-f42.google.com with SMTP id es6so2416263qvb.7 for ; Tue, 24 Nov 2020 11:21:00 -0800 (PST) Received: from rekt.redhat.com ([2804:431:c7c7:d88a:482:7c39:5cca:96f6]) by smtp.gmail.com with ESMTPSA id l79sm88837qke.1.2020.11.24.11.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 11:20:59 -0800 (PST) X-MC-Unique: RbE4_Z4JMU-qsJN4QGqoAA-1 X-MC-Unique: LwLChbOGO_i8oTMzvMI6hA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nKKYuapGPCFdQhmkouPYdBlztwppnkqoOSs4G1fYdvM=; b=GXVs8r4ak3nJzl4XtdVWCPEKHJTOxgNfZq1xKeNEUEF0z/xUzLUPXSN/wY7cWIq/px UM6jDLNomlOoP71/sqr4OsMg7WnYrNwcKb+wTTw8WjFJliCPl4yIid94rXKTBysEw6SF 0ujmS2IpyDzVUvecsbqJ5NOZEO9JCX3BY+dLaxm+EGAYu5S4p2aDf6OVl+nBlae47Cok sIiCbY5fifRlLujqsMES0TjQxaswMyC3zCHrmxMERqRgRyHOHJkHTQVWfKRL7Tmsq669 tqWO3UlMpayv+P7XLaYhzDhR9rqdDJRMqWJUxG6afQFGOXXjj9Cp8An4tWAZzWLdy/Hf XVSg== X-Gm-Message-State: AOAM531vIpG/l1KaDoBo3XyFrBdt9bYwcmh7n+QdvHlsJx9HXVSFna3+ /bQR2gPdXE0+DdGgOygplBafYw5xSC0= X-Google-Smtp-Source: ABdhPJzkc0wIQK/kuXMvodDS4DXAl7aBjPyje/0lEiH2bZBRFhB7LtlyvbfoboVG4WuWDX72laVgRw== X-Received: by 2002:a0c:9ad8:: with SMTP id k24mr6601496qvf.28.1606245659903; Tue, 24 Nov 2020 11:20:59 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 05/21] domain_conf.c: do not leak 'video' in virDomainDefParseXML() Date: Tue, 24 Nov 2020 16:20:19 -0300 Message-Id: <20201124192035.2343063-6-danielhb413@gmail.com> In-Reply-To: <20201124192035.2343063-1-danielhb413@gmail.com> References: <20201124192035.2343063-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.15 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 Content-Type: text/plain; charset="utf-8" The 'video' pointer is only being freed on error path, meaning that we're leaking it after each loop restart. There are more opportunities for auto cleanups of virDomainVideoDef pointers, so let's register AUTOPTR_CLEANUP_FUNC for it to use g_autoptr() later on. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 4 +--- src/conf/domain_conf.h | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c2e5ed5680..88c647f943 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -22233,7 +22233,7 @@ virDomainDefParseXML(xmlDocPtr xml, if (n) def->videos =3D g_new0(virDomainVideoDefPtr, n); for (i =3D 0; i < n; i++) { - virDomainVideoDefPtr video; + g_autoptr(virDomainVideoDef) video =3D NULL; ssize_t insertAt =3D -1; =20 if (!(video =3D virDomainVideoDefParseXML(xmlopt, nodes[i], @@ -22242,7 +22242,6 @@ virDomainDefParseXML(xmlDocPtr xml, =20 if (video->primary) { if (def->nvideos !=3D 0 && def->videos[0]->primary) { - virDomainVideoDefFree(video); virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Only one primary video device is support= ed")); goto error; @@ -22254,7 +22253,6 @@ virDomainDefParseXML(xmlDocPtr xml, insertAt, def->nvideos, video) < 0) { - virDomainVideoDefFree(video); goto error; } } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 96e6c34553..ff82da7f7e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3083,6 +3083,7 @@ void virDomainNVRAMDefFree(virDomainNVRAMDefPtr def); void virDomainWatchdogDefFree(virDomainWatchdogDefPtr def); virDomainVideoDefPtr virDomainVideoDefNew(virDomainXMLOptionPtr xmlopt); void virDomainVideoDefFree(virDomainVideoDefPtr def); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainVideoDef, virDomainVideoDefFree); void virDomainVideoDefClear(virDomainVideoDefPtr def); virDomainHostdevDefPtr virDomainHostdevDefNew(void); void virDomainHostdevDefClear(virDomainHostdevDefPtr def); --=20 2.26.2