From nobody Tue Feb 10 21:40:33 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=1613152564; cv=none; d=zohomail.com; s=zohoarc; b=IBdP6PlrTVAWT7iFOZBlG+e/VXgmkxAZkpWdi8f2nwAdMYm2f84d8UtpjpChM1vLb30+F+KDjTf2/UnFIDGFAIUnWfBwJbcVI1eWCqTB9pJZ3Nv/IGLjdEQ9M8t6rXHXFzyLRlXmI2irHwStFt5LwZrCfqTsMae97RcjZELYfB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152564; 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=ykmMdI/yH+L6NnLWSbBsbSbqs0aC3/ZygE3GDdlSvSU=; b=iL6E96fzbNPxqaFxT7haY8Lz6zyh4LHxNtOuHMFbLvUeCr5s/rYiNxLzgppLPe2ZlnEXY7DZIn/2XB/+ripUaeVK04auwBN3IUJ96qdoZFIA3FGY9QAI9C1/qxb5sg0SPrGD/yINQMEMJUYSaHQoqvKTRzUr3FNLmyh5MY3U9fU= 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 1613152563979120.56596654257169; Fri, 12 Feb 2021 09:56:03 -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-187-MSflDfrSPV61N1ps-DDqqQ-1; Fri, 12 Feb 2021 12:55:58 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6D70DBBEE5; Fri, 12 Feb 2021 17:55:52 +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 1EC7110074E0; Fri, 12 Feb 2021 17:55:50 +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 D661E18095CC; Fri, 12 Feb 2021 17:55:48 +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 11CHtlEU010526 for ; Fri, 12 Feb 2021 12:55:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3C76218813; Fri, 12 Feb 2021 17:55:47 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D03058823 for ; Fri, 12 Feb 2021 17:55:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152561; 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=ykmMdI/yH+L6NnLWSbBsbSbqs0aC3/ZygE3GDdlSvSU=; b=ckGIENbzZ2a2mG+mhLwaXjz/oYAmaGGTAw48FVICEOaDJvZPL997VnEeyFFoczIGJxYraD KB8iWGD5s7Uz5wCqhQiDvWDV6IWfzQ6DEZC5I7xNOFRF+ZvZdFeeRcCswG7jVkNUnrqpMd yrUBv4lYIQps/elg+k0Z1jJdnF+b8Ls= X-MC-Unique: MSflDfrSPV61N1ps-DDqqQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 01/25] virLockDaemonPreExecRestart: Refactor memory cleanup Date: Fri, 12 Feb 2021 18:55:14 +0100 Message-Id: <6adcd92be15dd5abbf8d9e40590256b376925d27.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.84 on 10.5.11.22 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/locking/lock_daemon.c | 81 +++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 46 deletions(-) diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 94fe374df6..5913c0cb9c 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -697,87 +697,76 @@ virLockDaemonPreExecRestart(const char *state_file, virNetDaemonPtr dmn, char **argv) { - virJSONValuePtr child; - char *state =3D NULL; - virJSONValuePtr object =3D virJSONValueNewObject(); - char *magic =3D NULL; - virHashKeyValuePairPtr pairs =3D NULL, tmp; - virJSONValuePtr lockspaces; + g_autoptr(virJSONValue) object =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) lockspaces =3D virJSONValueNewArray(); + g_autoptr(virJSONValue) defaultLockspace =3D NULL; + g_autoptr(virJSONValue) daemon =3D NULL; + g_autofree char *state =3D NULL; + g_autofree char *magic =3D NULL; + g_autofree virHashKeyValuePairPtr pairs =3D NULL; + virHashKeyValuePairPtr tmp; VIR_DEBUG("Running pre-restart exec"); - if (!(child =3D virNetDaemonPreExecRestart(dmn))) - goto cleanup; - - if (virJSONValueObjectAppend(object, "daemon", child) < 0) { - virJSONValueFree(child); - goto cleanup; - } - - if (!(child =3D virLockSpacePreExecRestart(lockDaemon->defaultLockspac= e))) - goto cleanup; - - if (virJSONValueObjectAppend(object, "defaultLockspace", child) < 0) { - virJSONValueFree(child); - goto cleanup; - } + if (!(daemon =3D virNetDaemonPreExecRestart(dmn))) + return -1; - lockspaces =3D virJSONValueNewArray(); + if (virJSONValueObjectAppend(object, "daemon", daemon) < 0) + return -1; + daemon =3D NULL; - if (virJSONValueObjectAppend(object, "lockspaces", lockspaces) < 0) { - virJSONValueFree(lockspaces); - goto cleanup; - } + if (!(defaultLockspace =3D virLockSpacePreExecRestart(lockDaemon->defa= ultLockspace))) + return -1; + if (virJSONValueObjectAppend(object, "defaultLockspace", defaultLocksp= ace) < 0) + return -1; + defaultLockspace =3D NULL; tmp =3D pairs =3D virHashGetItems(lockDaemon->lockspaces, NULL, false); while (tmp && tmp->key) { virLockSpacePtr lockspace =3D (virLockSpacePtr)tmp->value; + g_autoptr(virJSONValue) child =3D NULL; if (!(child =3D virLockSpacePreExecRestart(lockspace))) - goto cleanup; + return -1; - if (virJSONValueArrayAppend(lockspaces, child) < 0) { - virJSONValueFree(child); - goto cleanup; - } + if (virJSONValueArrayAppend(lockspaces, child) < 0) + return -1; + child =3D NULL; tmp++; } + if (virJSONValueObjectAppend(object, "lockspaces", lockspaces) < 0) + return -1; + lockspaces =3D NULL; + if (!(magic =3D virLockDaemonGetExecRestartMagic())) - goto cleanup; + return -1; if (virJSONValueObjectAppendString(object, "magic", magic) < 0) - goto cleanup; + return -1; if (!(state =3D virJSONValueToString(object, true))) - goto cleanup; + return -1; VIR_DEBUG("Saving state %s", state); - if (virFileWriteStr(state_file, - state, 0700) < 0) { + if (virFileWriteStr(state_file, state, 0700) < 0) { virReportSystemError(errno, - _("Unable to save state file %s"), - state_file); - goto cleanup; + _("Unable to save state file %s"), state_file= ); + return -1; } if (execvp(argv[0], argv) < 0) { virReportSystemError(errno, "%s", _("Unable to restart self")); - goto cleanup; + return -1; } abort(); /* This should be impossible to reach */ - cleanup: - VIR_FREE(magic); - VIR_FREE(pairs); - VIR_FREE(state); - virJSONValueFree(object); - return -1; + return 0; } --=20 2.29.2