From nobody Tue Feb 10 07:39:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1613152638; cv=none; d=zohomail.com; s=zohoarc; b=YcpLp4V5oI6DnNFK7Wj7bIRgXwqZ9e5PqhvYvDNHYxhVIbs7U7HGOC7RD3aETSjZjn3Af0Zf+VyYzrfIwCYoIOLLeDT87s00hrkifJa0mB27DG0w8G95ghu9/3DI7i2Jdd+mbbe3PNkkDTY2pz63ksgccv9NrGeOaZJkuT0mwr8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152638; 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=xh5MmDGGEsAwDEyLeAntX56sx0s9fwVdbN3A01UoaRs=; b=g3EC7m3D3LuMC8P0DcRJr3x44RGg1dCUFI+0Go5NL304oGY3cVNmPwczfKNrWVGUXWpXDgT9xRctVaNQ9jcY3nW5HoGwU0Z+81oI0xNdqv30l0OKau46EBO9weRSCYjNgWMEMn3DJa5NWSVdokdzIJ7LfAV/UUtkW9rslfD2hlw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613152637960554.9151431946765; Fri, 12 Feb 2021 09:57:17 -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-290-aR3yHXuRMhSCb7JgAK4Bvg-1; Fri, 12 Feb 2021 12:57:11 -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 09F3A1084C84; Fri, 12 Feb 2021 17:56:37 +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 D889660BE5; Fri, 12 Feb 2021 17:56:36 +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 9E6AD18095CE; Fri, 12 Feb 2021 17:56:36 +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 11CHuXL7010834 for ; Fri, 12 Feb 2021 12:56:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id C869D7192B; Fri, 12 Feb 2021 17:56:32 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD27A5C3FD for ; Fri, 12 Feb 2021 17:56:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152636; 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=xh5MmDGGEsAwDEyLeAntX56sx0s9fwVdbN3A01UoaRs=; b=cYOiOICjXmpMVcxycqqz1sUMd4ZpR5VKJwnTrlkSHnBK+KrSVtEnya2ymPTEEkPviFePqC AAin0rAtC3fgG8Iddz+Sf7AjnKV3rW8wTa0WvH+eYYf1TeJt896RjlD5KYt2lCtwJkz/fc zXu7KscqObXamREjxEdBG/B8gezZ/0A= X-MC-Unique: aR3yHXuRMhSCb7JgAK4Bvg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 09/25] virLockSpacePreExecRestart: Refactor memory cleanup Date: Fri, 12 Feb 2021 18:55:22 +0100 Message-Id: <3b14ecf6d2de8ed80fe4aef0bfd231467cc2a248.1613152441.git.pkrempa@redhat.com> In-Reply-To: References: 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.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 using the 'g_auto*' helpers. Signed-off-by: Peter Krempa --- src/util/virlockspace.c | 51 +++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index 7df319004e..1b6b51b649 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -418,9 +418,10 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSON= ValuePtr object) virJSONValuePtr virLockSpacePreExecRestart(virLockSpacePtr lockspace) { - virJSONValuePtr object =3D virJSONValueNewObject(); - virJSONValuePtr resources; - virHashKeyValuePairPtr pairs =3D NULL, tmp; + g_autoptr(virJSONValue) object =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) resources =3D virJSONValueNewArray(); + g_autofree virHashKeyValuePairPtr pairs =3D NULL; + virHashKeyValuePairPtr tmp; virMutexLock(&lockspace->lock); @@ -428,25 +429,14 @@ virJSONValuePtr virLockSpacePreExecRestart(virLockSpa= cePtr lockspace) virJSONValueObjectAppendString(object, "directory", lockspace->dir= ) < 0) goto error; - resources =3D virJSONValueNewArray(); - - if (virJSONValueObjectAppend(object, "resources", resources) < 0) { - virJSONValueFree(resources); - goto error; - } tmp =3D pairs =3D virHashGetItems(lockspace->resources, NULL, false); while (tmp && tmp->value) { virLockSpaceResourcePtr res =3D (virLockSpaceResourcePtr)tmp->valu= e; - virJSONValuePtr child =3D virJSONValueNewObject(); - virJSONValuePtr owners =3D NULL; + g_autoptr(virJSONValue) child =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) owners =3D virJSONValueNewArray(); size_t i; - if (virJSONValueArrayAppend(resources, child) < 0) { - virJSONValueFree(child); - goto error; - } - if (virJSONValueObjectAppendString(child, "name", res->name) < 0 || virJSONValueObjectAppendString(child, "path", res->path) < 0 || virJSONValueObjectAppendNumberInt(child, "fd", res->fd) < 0 || @@ -460,34 +450,35 @@ virJSONValuePtr virLockSpacePreExecRestart(virLockSpa= cePtr lockspace) goto error; } - owners =3D virJSONValueNewArray(); - - if (virJSONValueObjectAppend(child, "owners", owners) < 0) { - virJSONValueFree(owners); - goto error; - } - for (i =3D 0; i < res->nOwners; i++) { - virJSONValuePtr owner =3D virJSONValueNewNumberUlong(res->owne= rs[i]); + g_autoptr(virJSONValue) owner =3D virJSONValueNewNumberUlong(r= es->owners[i]); if (!owner) goto error; - if (virJSONValueArrayAppend(owners, owner) < 0) { - virJSONValueFree(owner); + if (virJSONValueArrayAppend(owners, owner) < 0) goto error; - } + owner =3D NULL; } + if (virJSONValueObjectAppend(child, "owners", owners) < 0) + goto error; + owners =3D NULL; + + if (virJSONValueArrayAppend(resources, child) < 0) + goto error; + child =3D NULL; + tmp++; } - VIR_FREE(pairs); + + if (virJSONValueObjectAppend(object, "resources", resources) < 0) + goto error; + resources =3D NULL; virMutexUnlock(&lockspace->lock); return object; error: - VIR_FREE(pairs); - virJSONValueFree(object); virMutexUnlock(&lockspace->lock); return NULL; } --=20 2.29.2