From nobody Mon Feb 9 01:21:51 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; 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=1614183475; cv=none; d=zohomail.com; s=zohoarc; b=YnK0StLNtHVPzjqhwEoxLjT4X5dfTHGdqPEijMZNG7O6HYNvFpVRSuCJltVdTI/hjq0PgPiLhoJOc4cmEwa2J0y26adfzc8Cp1SSxUdKv5TCAi9wb/txvtdII0yRCd4iQqUnScSz4iF2ZYKg6FmVvJTlrogvgIuaBl4g/CwVnJo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614183475; h=Content-Type:Content-Transfer-Encoding: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=PuCx6MAkwE/Kjlujg66QrxH6oquR9HTseqkWP8tgfTU=; b=EyOQdo1xr1PqN+AUME4irWgdDavdY/l2kOCJIWaLsciIiMEiTG6ka9zvh8ULLk9YdL7YVeLAAEDyYaXBHDmeCQysDbEHvZIHvruNq9/FTTiWzzXSm+jgD0iHOsuXmuyn9NsDDgtLtFGJOMD3nXOQuqMygaqKoO4H9a5enPY+PsE= 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 1614183475210436.97734510630676; Wed, 24 Feb 2021 08:17:55 -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-507-G7VpPMcsNfuBBozC-hqqKA-1; Wed, 24 Feb 2021 11:17:48 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 097B980403D; Wed, 24 Feb 2021 16:17:42 +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 D867360C64; Wed, 24 Feb 2021 16:17:41 +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 997B018089D4; Wed, 24 Feb 2021 16:17:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11OGHYtT015578 for ; Wed, 24 Feb 2021 11:17:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9FBD660CDE; Wed, 24 Feb 2021 16:17:34 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2A8A60862 for ; Wed, 24 Feb 2021 16:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614183473; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=PuCx6MAkwE/Kjlujg66QrxH6oquR9HTseqkWP8tgfTU=; b=L1ZxdObHdm6Z+abJxsGWgKoVbXqP5zZ4g/1TW9Ka7f/aF6TEW5xoDm3753hXcZN69SqqOT T8dqdnCgroQKWxC7wmWoJRi20ATliuw/HMq1cTuizIzG7FiFJh7u68C38lD6h3CZfxN8aC 5vZG9icixDoWhGIbuB0IDuKY80dfXzc= X-MC-Unique: G7VpPMcsNfuBBozC-hqqKA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 10/33] virDomainDefSetMetadata: Rework memory handling Date: Wed, 24 Feb 2021 17:16:45 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.12 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" Switch to use g_autoptr for 'doc' and 'new' local variables. Additionally report proper error when 'xmlAddChild' fails because OOM is not the only error it can report. Signed-off-by: Peter Krempa --- src/conf/domain_conf.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6f4487fcfc..46620d38ed 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30423,15 +30423,14 @@ virDomainDefSetMetadata(virDomainDefPtr def, const char *key, const char *uri) { - xmlDocPtr doc =3D NULL; + g_autoptr(xmlDoc) doc =3D NULL; xmlNodePtr old; - xmlNodePtr new =3D NULL; - int ret =3D -1; + g_autoptr(xmlNode) new =3D NULL; if (type >=3D VIR_DOMAIN_METADATA_LAST) { virReportError(VIR_ERR_INVALID_ARG, _("unknown metadata type '%d'"), type); - goto cleanup; + return -1; } switch ((virDomainMetadataType) type) { @@ -30451,23 +30450,24 @@ virDomainDefSetMetadata(virDomainDefPtr def, case VIR_DOMAIN_METADATA_ELEMENT: if (metadata) { + /* parse and modify the xml from the user */ if (!(doc =3D virXMLParseString(metadata, _("(metadata_xml)"))= )) - goto cleanup; + return -1; if (virXMLInjectNamespace(doc->children, uri, key) < 0) - goto cleanup; + return -1; /* create the root node if needed */ if (!def->metadata && !(def->metadata =3D xmlNewNode(NULL, (unsigned char *)"met= adata"))) { virReportOOMError(); - goto cleanup; + return -1; } if (!(new =3D xmlCopyNode(doc->children, 1))) { virReportOOMError(); - goto cleanup; + return -1; } } @@ -30477,11 +30477,13 @@ virDomainDefSetMetadata(virDomainDefPtr def, xmlFreeNode(old); } - if (new && - !(xmlAddChild(def->metadata, new))) { - xmlFreeNode(new); - virReportOOMError(); - goto cleanup; + if (new) { + if (!(xmlAddChild(def->metadata, new))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to add metadata to XML document")= ); + return -1; + } + new =3D NULL; } break; @@ -30490,11 +30492,7 @@ virDomainDefSetMetadata(virDomainDefPtr def, break; } - ret =3D 0; - - cleanup: - xmlFreeDoc(doc); - return ret; + return 0; } --=20 2.29.2