From nobody Sun Feb 8 23:05:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 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=1571576211; cv=none; d=zoho.com; s=zohoarc; b=WdkEKkfFRlSznwFBuUMZ76/w0yZv2jh5CzEByv2EZ0E+JxWVASku5MnWSFoIUohli7LqOnFv8gqV2+RuPzptZl2knmNAfeeWPeh8MHH6OuY7Nm+Bo6At+Bw73RcGzMdTD9kTbhd8wc+XC1vQQJt0sVuD1iXdAjs4sjS/j8Of7hI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571576211; 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=UGvF+edK9Y8UpNvDXeYdj860OJIBZv2EOPTKxwDe5qo=; b=kn8OaP4vk891TIWxzutqs8acx5RTPRlZzVZAQz8JJCrgXoN4ejRyB22PmhIVoswNMURA7NjtMWfaynOcynRDbVf63oc92KddkFSQYL95h0hUGNgldALYIpYs4X5Oo7bAdrDTNYcSj4sQ9aAwIInc2Np/JQpMNIOsA81JrknSP6E= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1571576211374781.7557846968149; Sun, 20 Oct 2019 05:56:51 -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-373-tnyzh_kaOyGEM80chjuJlg-1; Sun, 20 Oct 2019 08:56:47 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1D45E107AFC6; Sun, 20 Oct 2019 12:56:43 +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 EDA21194B9; Sun, 20 Oct 2019 12:56:42 +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 AE9A3180B536; Sun, 20 Oct 2019 12:56:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9KCu1kH023537 for ; Sun, 20 Oct 2019 08:56:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6DAEE3CC8; Sun, 20 Oct 2019 12:56:01 +0000 (UTC) Received: from lpt.redhat.com (ovpn-200-23.brq.redhat.com [10.40.200.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC3B0194B9 for ; Sun, 20 Oct 2019 12:56:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571576210; 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=UGvF+edK9Y8UpNvDXeYdj860OJIBZv2EOPTKxwDe5qo=; b=LwFLSAhcjYqmfQRa2E1NnCkkIuv0Tbe9jl3yuCzPscgcES5v3Q+sD7RfqQhOWLFx/A9Ahj 2Qw993Kq4HF/x1TxYw0eygTSQloapIu3SpLo51Alnj2Uexkwb3tGXCe2fUL96EiLCELbgr yRGixVKPqJcpW8W1vicnVC3zHk5u4bk= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Sun, 20 Oct 2019 14:55:41 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 23/34] remote: use g_strdup instead of VIR_STRDUP 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.23 X-MC-Unique: tnyzh_kaOyGEM80chjuJlg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Replace all occurrences of if (VIR_STRDUP(a, b) < 0) /* effectively dead code */ with: a =3D g_strdup(b); Signed-off-by: J=C3=A1n Tomko --- src/remote/remote_daemon.c | 15 +- src/remote/remote_daemon_config.c | 24 +-- src/remote/remote_daemon_dispatch.c | 222 +++++++++++----------------- src/remote/remote_driver.c | 106 +++++-------- 4 files changed, 132 insertions(+), 235 deletions(-) diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index e87ff12512..7e63e18034 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -1100,18 +1100,12 @@ int main(int argc, char **argv) { =20 case 'p': VIR_FREE(pid_file); - if (VIR_STRDUP_QUIET(pid_file, optarg) < 0) { - VIR_ERROR(_("Can't allocate memory")); - exit(EXIT_FAILURE); - } + pid_file =3D g_strdup(optarg); break; =20 case 'f': VIR_FREE(remote_config_file); - if (VIR_STRDUP_QUIET(remote_config_file, optarg) < 0) { - VIR_ERROR(_("Can't allocate memory")); - exit(EXIT_FAILURE); - } + remote_config_file =3D g_strdup(optarg); break; =20 case 'V': @@ -1222,10 +1216,7 @@ int main(int argc, char **argv) { =20 /* Ensure the rundir exists (on tmpfs on some systems) */ if (privileged) { - if (VIR_STRDUP_QUIET(run_dir, RUNSTATEDIR "/libvirt") < 0) { - VIR_ERROR(_("Can't allocate memory")); - goto cleanup; - } + run_dir =3D g_strdup(RUNSTATEDIR "/libvirt"); } else { run_dir =3D virGetUserRuntimeDirectory(); =20 diff --git a/src/remote/remote_daemon_config.c b/src/remote/remote_daemon_c= onfig.c index 4c712bf2dc..3187c9acb1 100644 --- a/src/remote/remote_daemon_config.c +++ b/src/remote/remote_daemon_config.c @@ -77,9 +77,7 @@ int daemonConfigFilePath(bool privileged, char **configfile) { if (privileged) { - if (VIR_STRDUP(*configfile, - SYSCONFDIR "/libvirt/" DAEMON_NAME ".conf") < 0) - goto error; + *configfile =3D g_strdup(SYSCONFDIR "/libvirt/" DAEMON_NAME ".conf= "); } else { char *configdir =3D NULL; =20 @@ -115,9 +113,8 @@ daemonConfigNew(bool privileged G_GNUC_UNUSED) # endif /* ! LIBVIRTD */ data->listen_tcp =3D 0; =20 - if (VIR_STRDUP(data->tls_port, LIBVIRTD_TLS_PORT) < 0 || - VIR_STRDUP(data->tcp_port, LIBVIRTD_TCP_PORT) < 0) - goto error; + data->tls_port =3D g_strdup(LIBVIRTD_TLS_PORT); + data->tcp_port =3D g_strdup(LIBVIRTD_TCP_PORT); #endif /* !WITH_IP */ =20 /* Only default to PolicyKit if running as root */ @@ -133,11 +130,9 @@ daemonConfigNew(bool privileged G_GNUC_UNUSED) } #endif =20 - if (VIR_STRDUP(data->unix_sock_rw_perms, - data->auth_unix_rw =3D=3D REMOTE_AUTH_POLKIT ? "0777" := "0700") < 0 || - VIR_STRDUP(data->unix_sock_ro_perms, "0777") < 0 || - VIR_STRDUP(data->unix_sock_admin_perms, "0700") < 0) - goto error; + data->unix_sock_rw_perms =3D g_strdup(data->auth_unix_rw =3D=3D REMOTE= _AUTH_POLKIT ? "0777" : "0700"); + data->unix_sock_ro_perms =3D g_strdup("0777"); + data->unix_sock_admin_perms =3D g_strdup("0700"); =20 #ifdef WITH_IP # if WITH_SASL @@ -176,10 +171,6 @@ daemonConfigNew(bool privileged G_GNUC_UNUSED) data->ovs_timeout =3D VIR_NETDEV_OVS_DEFAULT_TIMEOUT; =20 return data; - - error: - daemonConfigFree(data); - return NULL; } =20 void @@ -266,8 +257,7 @@ daemonConfigLoadOptions(struct daemonConfig *data, */ if (data->auth_unix_rw =3D=3D REMOTE_AUTH_POLKIT) { VIR_FREE(data->unix_sock_rw_perms); - if (VIR_STRDUP(data->unix_sock_rw_perms, "0777") < 0) - goto error; + data->unix_sock_rw_perms =3D g_strdup("0777"); } #endif if (remoteConfigGetAuth(conf, filename, "auth_unix_ro", &data->auth_un= ix_ro) < 0) diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index 56a46a13be..203aeff8c3 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -509,9 +509,8 @@ remoteRelayDomainEventIOError(virConnectPtr conn, =20 /* build return data */ memset(&data, 0, sizeof(data)); - if (VIR_STRDUP(data.srcPath, srcPath) < 0 || - VIR_STRDUP(data.devAlias, devAlias) < 0) - goto error; + data.srcPath =3D g_strdup(srcPath); + data.devAlias =3D g_strdup(devAlias); if (make_nonnull_domain(&data.dom, dom) < 0) goto error; data.action =3D action; @@ -559,10 +558,9 @@ remoteRelayDomainEventIOErrorReason(virConnectPtr conn, =20 /* build return data */ memset(&data, 0, sizeof(data)); - if (VIR_STRDUP(data.srcPath, srcPath) < 0 || - VIR_STRDUP(data.devAlias, devAlias) < 0 || - VIR_STRDUP(data.reason, reason) < 0) - goto error; + data.srcPath =3D g_strdup(srcPath); + data.devAlias =3D g_strdup(devAlias); + data.reason =3D g_strdup(reason); data.action =3D action; =20 if (make_nonnull_domain(&data.dom, dom) < 0) @@ -623,21 +621,23 @@ remoteRelayDomainEventGraphics(virConnectPtr conn, data.phase =3D phase; data.local.family =3D local->family; data.remote.family =3D remote->family; - if (VIR_STRDUP(data.authScheme, authScheme) < 0 || - VIR_STRDUP(data.local.node, local->node) < 0 || - VIR_STRDUP(data.local.service, local->service) < 0 || - VIR_STRDUP(data.remote.node, remote->node) < 0 || - VIR_STRDUP(data.remote.service, remote->service) < 0) - goto error; + data.authScheme =3D g_strdup(authScheme); + + data.local.node =3D g_strdup(local->node); + + data.local.service =3D g_strdup(local->service); + + data.remote.node =3D g_strdup(remote->node); + + data.remote.service =3D g_strdup(remote->service); =20 data.subject.subject_len =3D subject->nidentity; if (VIR_ALLOC_N(data.subject.subject_val, data.subject.subject_len) < = 0) goto error; =20 for (i =3D 0; i < data.subject.subject_len; i++) { - if (VIR_STRDUP(data.subject.subject_val[i].type, subject->identiti= es[i].type) < 0 || - VIR_STRDUP(data.subject.subject_val[i].name, subject->identiti= es[i].name) < 0) - goto error; + data.subject.subject_val[i].type =3D g_strdup(subject->identities[= i].type); + data.subject.subject_val[i].name =3D g_strdup(subject->identities[= i].name); } if (make_nonnull_domain(&data.dom, dom) < 0) goto error; @@ -683,8 +683,7 @@ remoteRelayDomainEventBlockJob(virConnectPtr conn, =20 /* build return data */ memset(&data, 0, sizeof(data)); - if (VIR_STRDUP(data.path, path) < 0) - return -1; + data.path =3D g_strdup(path); data.type =3D type; data.status =3D status; if (make_nonnull_domain(&data.dom, dom) < 0) @@ -776,18 +775,19 @@ remoteRelayDomainEventDiskChange(virConnectPtr conn, =20 /* build return data */ memset(&data, 0, sizeof(data)); - if (oldSrcPath && - ((VIR_ALLOC(data.oldSrcPath) < 0) || - VIR_STRDUP(*(data.oldSrcPath), oldSrcPath) < 0)) - goto error; + if (oldSrcPath) { + if (VIR_ALLOC(data.oldSrcPath) < 0) + goto error; + *(data.oldSrcPath) =3D g_strdup(oldSrcPath); + } =20 - if (newSrcPath && - ((VIR_ALLOC(data.newSrcPath) < 0) || - VIR_STRDUP(*(data.newSrcPath), newSrcPath) < 0)) - goto error; + if (newSrcPath) { + if (VIR_ALLOC(data.newSrcPath) < 0) + goto error; + *(data.newSrcPath) =3D g_strdup(newSrcPath); + } =20 - if (VIR_STRDUP(data.devAlias, devAlias) < 0) - goto error; + data.devAlias =3D g_strdup(devAlias); data.reason =3D reason; =20 if (make_nonnull_domain(&data.dom, dom) < 0) @@ -835,8 +835,7 @@ remoteRelayDomainEventTrayChange(virConnectPtr conn, /* build return data */ memset(&data, 0, sizeof(data)); =20 - if (VIR_STRDUP(data.devAlias, devAlias) < 0) - return -1; + data.devAlias =3D g_strdup(devAlias); data.reason =3D reason; =20 if (make_nonnull_domain(&data.dom, dom) < 0) @@ -1052,8 +1051,7 @@ remoteRelayDomainEventDeviceRemoved(virConnectPtr con= n, /* build return data */ memset(&data, 0, sizeof(data)); =20 - if (VIR_STRDUP(data.devAlias, devAlias) < 0) - return -1; + data.devAlias =3D g_strdup(devAlias); =20 if (make_nonnull_domain(&data.dom, dom) < 0) goto error; @@ -1103,8 +1101,7 @@ remoteRelayDomainEventBlockJob2(virConnectPtr conn, /* build return data */ memset(&data, 0, sizeof(data)); data.callbackID =3D callback->callbackID; - if (VIR_STRDUP(data.dst, dst) < 0) - return -1; + data.dst =3D g_strdup(dst); data.type =3D type; data.status =3D status; if (make_nonnull_domain(&data.dom, dom) < 0) @@ -1228,8 +1225,7 @@ remoteRelayDomainEventDeviceAdded(virConnectPtr conn, /* build return data */ memset(&data, 0, sizeof(data)); =20 - if (VIR_STRDUP(data.devAlias, devAlias) < 0) - return -1; + data.devAlias =3D g_strdup(devAlias); =20 if (make_nonnull_domain(&data.dom, dom) < 0) goto error; @@ -1352,8 +1348,7 @@ remoteRelayDomainEventDeviceRemovalFailed(virConnectP= tr conn, /* build return data */ memset(&data, 0, sizeof(data)); =20 - if (VIR_STRDUP(data.devAlias, devAlias) < 0) - return -1; + data.devAlias =3D g_strdup(devAlias); =20 if (make_nonnull_domain(&data.dom, dom) < 0) goto error; @@ -1395,9 +1390,9 @@ remoteRelayDomainEventMetadataChange(virConnectPtr co= nn, =20 data.type =3D type; if (nsuri) { - if (VIR_ALLOC(data.nsuri) < 0 || - VIR_STRDUP(*(data.nsuri), nsuri) < 0) + if (VIR_ALLOC(data.nsuri) < 0) goto error; + *(data.nsuri) =3D g_strdup(nsuri); } =20 if (make_nonnull_domain(&data.dom, dom) < 0) @@ -1440,12 +1435,11 @@ remoteRelayDomainEventBlockThreshold(virConnectPtr = conn, /* build return data */ memset(&data, 0, sizeof(data)); data.callbackID =3D callback->callbackID; - if (VIR_STRDUP(data.dev, dev) < 0) - goto error; + data.dev =3D g_strdup(dev); if (path) { - if (VIR_ALLOC(data.path) < 0 || - VIR_STRDUP(*(data.path), path) < 0) + if (VIR_ALLOC(data.path) < 0) goto error; + *(data.path) =3D g_strdup(path); } data.threshold =3D threshold; data.excess =3D excess; @@ -1798,14 +1792,14 @@ remoteRelayDomainQemuMonitorEvent(virConnectPtr con= n, /* build return data */ memset(&data, 0, sizeof(data)); data.callbackID =3D callback->callbackID; - if (VIR_STRDUP(data.event, event) < 0) - goto error; + data.event =3D g_strdup(event); data.seconds =3D seconds; data.micros =3D micros; - if (details && - ((VIR_ALLOC(data.details) < 0) || - VIR_STRDUP(*(data.details), details) < 0)) - goto error; + if (details) { + if (VIR_ALLOC(data.details) < 0) + goto error; + *(data.details) =3D g_strdup(details); + } if (make_nonnull_domain(&data.dom, dom) < 0) goto error; =20 @@ -2886,11 +2880,7 @@ remoteDispatchDomainGetSecurityLabelList(virNetServe= rPtr server G_GNUC_UNUSED, for (i =3D 0; i < len; i++) { size_t label_len =3D strlen(seclabels[i].label) + 1; remote_domain_get_security_label_ret *cur =3D &ret->labels.labels_= val[i]; - if (VIR_STRDUP(cur->label.label_val, seclabels[i].label) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to copy security label")); - goto cleanup; - } + cur->label.label_val =3D g_strdup(seclabels[i].label); cur->label.label_len =3D label_len; cur->enforcing =3D seclabels[i].enforcing; } @@ -3560,8 +3550,7 @@ remoteDispatchNodeGetCPUStats(virNetServerPtr server = G_GNUC_UNUSED, =20 for (i =3D 0; i < nparams; ++i) { /* remoteDispatchClientRequest will free this: */ - if (VIR_STRDUP(ret->params.params_val[i].field, params[i].field) <= 0) - goto cleanup; + ret->params.params_val[i].field =3D g_strdup(params[i].field); =20 ret->params.params_val[i].value =3D params[i].value; } @@ -3629,8 +3618,7 @@ remoteDispatchNodeGetMemoryStats(virNetServerPtr serv= er G_GNUC_UNUSED, =20 for (i =3D 0; i < nparams; ++i) { /* remoteDispatchClientRequest will free this: */ - if (VIR_STRDUP(ret->params.params_val[i].field, params[i].field) <= 0) - goto cleanup; + ret->params.params_val[i].field =3D g_strdup(params[i].field); =20 ret->params.params_val[i].value =3D params[i].value; } @@ -4365,9 +4353,9 @@ remoteDispatchNodeDeviceGetParent(virNetServerPtr ser= ver G_GNUC_UNUSED, ret->parentName =3D NULL; } else { /* remoteDispatchClientRequest will free this. */ - if (VIR_ALLOC(ret->parentName) < 0 || - VIR_STRDUP(*(ret->parentName), parent) < 0) + if (VIR_ALLOC(ret->parentName) < 0) goto cleanup; + *(ret->parentName) =3D g_strdup(parent); } =20 rv =3D 0; @@ -6907,29 +6895,28 @@ remoteSerializeDHCPLease(remote_network_dhcp_lease = *lease_dst, virNetworkDHCPLea lease_dst->type =3D lease_src->type; lease_dst->prefix =3D lease_src->prefix; =20 - if (VIR_STRDUP(lease_dst->iface, lease_src->iface) < 0 || - VIR_STRDUP(lease_dst->ipaddr, lease_src->ipaddr) < 0) - goto error; + lease_dst->iface =3D g_strdup(lease_src->iface); + lease_dst->ipaddr =3D g_strdup(lease_src->ipaddr); =20 if (lease_src->mac) { - if (VIR_ALLOC(mac_tmp) < 0 || - VIR_STRDUP(*mac_tmp, lease_src->mac) < 0) + if (VIR_ALLOC(mac_tmp) < 0) goto error; + *mac_tmp =3D g_strdup(lease_src->mac); } if (lease_src->iaid) { - if (VIR_ALLOC(iaid_tmp) < 0 || - VIR_STRDUP(*iaid_tmp, lease_src->iaid) < 0) + if (VIR_ALLOC(iaid_tmp) < 0) goto error; + *iaid_tmp =3D g_strdup(lease_src->iaid); } if (lease_src->hostname) { - if (VIR_ALLOC(hostname_tmp) < 0 || - VIR_STRDUP(*hostname_tmp, lease_src->hostname) < 0) + if (VIR_ALLOC(hostname_tmp) < 0) goto error; + *hostname_tmp =3D g_strdup(lease_src->hostname); } if (lease_src->clientid) { - if (VIR_ALLOC(clientid_tmp) < 0 || - VIR_STRDUP(*clientid_tmp, lease_src->clientid) < 0) + if (VIR_ALLOC(clientid_tmp) < 0) goto error; + *clientid_tmp =3D g_strdup(lease_src->clientid); } =20 lease_dst->mac =3D mac_tmp; @@ -7188,14 +7175,11 @@ remoteDispatchDomainGetFSInfo(virNetServerPtr serve= r G_GNUC_UNUSED, =20 for (i =3D 0; i < ninfo; i++) { dst =3D &ret->info.info_val[i]; - if (VIR_STRDUP(dst->mountpoint, info[i]->mountpoint) < 0) - goto cleanup; + dst->mountpoint =3D g_strdup(info[i]->mountpoint); =20 - if (VIR_STRDUP(dst->name, info[i]->name) < 0) - goto cleanup; + dst->name =3D g_strdup(info[i]->name); =20 - if (VIR_STRDUP(dst->fstype, info[i]->fstype) < 0) - goto cleanup; + dst->fstype =3D g_strdup(info[i]->fstype); =20 ndisk =3D info[i]->ndevAlias; if (ndisk > REMOTE_DOMAIN_FSINFO_DISKS_MAX) { @@ -7209,11 +7193,8 @@ remoteDispatchDomainGetFSInfo(virNetServerPtr server= G_GNUC_UNUSED, if (VIR_ALLOC_N(dst->dev_aliases.dev_aliases_val, ndisk) <= 0) goto cleanup; =20 - for (j =3D 0; j < ndisk; j++) { - if (VIR_STRDUP(dst->dev_aliases.dev_aliases_val[j], - info[i]->devAlias[j]) < 0) - goto cleanup; - } + for (j =3D 0; j < ndisk; j++) + dst->dev_aliases.dev_aliases_val[j] =3D g_strdup(info[= i]->devAlias[j]); =20 dst->dev_aliases.dev_aliases_len =3D ndisk; } else { @@ -7281,13 +7262,13 @@ remoteSerializeDomainInterface(virDomainInterfacePt= r *ifaces, virDomainInterfacePtr iface =3D ifaces[i]; remote_domain_interface *iface_ret =3D &(ret->ifaces.ifaces_val[i]= ); =20 - if ((VIR_STRDUP(iface_ret->name, iface->name)) < 0) - goto cleanup; + iface_ret->name =3D g_strdup(iface->name); =20 - if (iface->hwaddr && - (VIR_ALLOC(iface_ret->hwaddr) < 0 || - VIR_STRDUP(*iface_ret->hwaddr, iface->hwaddr) < 0)) - goto cleanup; + if (iface->hwaddr) { + if (VIR_ALLOC(iface_ret->hwaddr) < 0) + goto cleanup; + *iface_ret->hwaddr =3D g_strdup(iface->hwaddr); + } =20 if (iface->naddrs > REMOTE_DOMAIN_IP_ADDR_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -7307,8 +7288,7 @@ remoteSerializeDomainInterface(virDomainInterfacePtr = *ifaces, remote_domain_ip_addr *ip_addr_ret =3D &(iface_ret->addrs.addrs_val[j]); =20 - if (VIR_STRDUP(ip_addr_ret->addr, ip_addr->addr) < 0) - goto cleanup; + ip_addr_ret->addr =3D g_strdup(ip_addr->addr); =20 ip_addr_ret->prefix =3D ip_addr->prefix; ip_addr_ret->type =3D ip_addr->type; @@ -7559,8 +7539,7 @@ static int make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainPtr dom_src) { dom_dst->id =3D dom_src->id; - if (VIR_STRDUP(dom_dst->name, dom_src->name) < 0) - return -1; + dom_dst->name =3D g_strdup(dom_src->name); memcpy(dom_dst->uuid, dom_src->uuid, VIR_UUID_BUFLEN); return 0; } @@ -7568,8 +7547,7 @@ make_nonnull_domain(remote_nonnull_domain *dom_dst, v= irDomainPtr dom_src) static int make_nonnull_network(remote_nonnull_network *net_dst, virNetworkPtr net_sr= c) { - if (VIR_STRDUP(net_dst->name, net_src->name) < 0) - return -1; + net_dst->name =3D g_strdup(net_src->name); memcpy(net_dst->uuid, net_src->uuid, VIR_UUID_BUFLEN); return 0; } @@ -7577,8 +7555,7 @@ make_nonnull_network(remote_nonnull_network *net_dst,= virNetworkPtr net_src) static int make_nonnull_network_port(remote_nonnull_network_port *port_dst, virNetwor= kPortPtr port_src) { - if (VIR_STRDUP(port_dst->net.name, port_src->net->name) < 0) - return -1; + port_dst->net.name =3D g_strdup(port_src->net->name); memcpy(port_dst->net.uuid, port_src->net->uuid, VIR_UUID_BUFLEN); memcpy(port_dst->uuid, port_src->uuid, VIR_UUID_BUFLEN); return 0; @@ -7588,20 +7565,15 @@ static int make_nonnull_interface(remote_nonnull_interface *interface_dst, virInterfacePtr interface_src) { - if (VIR_STRDUP(interface_dst->name, interface_src->name) < 0) - return -1; - if (VIR_STRDUP(interface_dst->mac, interface_src->mac) < 0) { - VIR_FREE(interface_dst->name); - return -1; - } + interface_dst->name =3D g_strdup(interface_src->name); + interface_dst->mac =3D g_strdup(interface_src->mac); return 0; } =20 static int make_nonnull_storage_pool(remote_nonnull_storage_pool *pool_dst, virStorag= ePoolPtr pool_src) { - if (VIR_STRDUP(pool_dst->name, pool_src->name) < 0) - return -1; + pool_dst->name =3D g_strdup(pool_src->name); memcpy(pool_dst->uuid, pool_src->uuid, VIR_UUID_BUFLEN); return 0; } @@ -7609,25 +7581,16 @@ make_nonnull_storage_pool(remote_nonnull_storage_po= ol *pool_dst, virStoragePoolP static int make_nonnull_storage_vol(remote_nonnull_storage_vol *vol_dst, virStorageVo= lPtr vol_src) { - if (VIR_STRDUP(vol_dst->pool, vol_src->pool) < 0) - return -1; - if (VIR_STRDUP(vol_dst->name, vol_src->name) < 0) { - VIR_FREE(vol_dst->pool); - return -1; - } - if (VIR_STRDUP(vol_dst->key, vol_src->key) < 0) { - VIR_FREE(vol_dst->pool); - VIR_FREE(vol_dst->name); - return -1; - } + vol_dst->pool =3D g_strdup(vol_src->pool); + vol_dst->name =3D g_strdup(vol_src->name); + vol_dst->key =3D g_strdup(vol_src->key); return 0; } =20 static int make_nonnull_node_device(remote_nonnull_node_device *dev_dst, virNodeDevic= ePtr dev_src) { - if (VIR_STRDUP(dev_dst->name, dev_src->name) < 0) - return -1; + dev_dst->name =3D g_strdup(dev_src->name); return 0; } =20 @@ -7636,16 +7599,14 @@ make_nonnull_secret(remote_nonnull_secret *secret_d= st, virSecretPtr secret_src) { memcpy(secret_dst->uuid, secret_src->uuid, VIR_UUID_BUFLEN); secret_dst->usageType =3D secret_src->usageType; - if (VIR_STRDUP(secret_dst->usageID, secret_src->usageID) < 0) - return -1; + secret_dst->usageID =3D g_strdup(secret_src->usageID); return 0; } =20 static int make_nonnull_nwfilter(remote_nonnull_nwfilter *nwfilter_dst, virNWFilterPt= r nwfilter_src) { - if (VIR_STRDUP(nwfilter_dst->name, nwfilter_src->name) < 0) - return -1; + nwfilter_dst->name =3D g_strdup(nwfilter_src->name); memcpy(nwfilter_dst->uuid, nwfilter_src->uuid, VIR_UUID_BUFLEN); return 0; } @@ -7653,20 +7614,15 @@ make_nonnull_nwfilter(remote_nonnull_nwfilter *nwfi= lter_dst, virNWFilterPtr nwfi static int make_nonnull_nwfilter_binding(remote_nonnull_nwfilter_binding *binding_dst= , virNWFilterBindingPtr binding_src) { - if (VIR_STRDUP(binding_dst->portdev, binding_src->portdev) < 0) - return -1; - if (VIR_STRDUP(binding_dst->filtername, binding_src->filtername) < 0) { - VIR_FREE(binding_dst->portdev); - return -1; - } + binding_dst->portdev =3D g_strdup(binding_src->portdev); + binding_dst->filtername =3D g_strdup(binding_src->filtername); return 0; } =20 static int make_nonnull_domain_checkpoint(remote_nonnull_domain_checkpoint *checkpoin= t_dst, virDomainCheckpointPtr checkpoint_src) { - if (VIR_STRDUP(checkpoint_dst->name, checkpoint_src->name) < 0) - return -1; + checkpoint_dst->name =3D g_strdup(checkpoint_src->name); if (make_nonnull_domain(&checkpoint_dst->dom, checkpoint_src->domain) = < 0) { VIR_FREE(checkpoint_dst->name); return -1; @@ -7677,8 +7633,7 @@ make_nonnull_domain_checkpoint(remote_nonnull_domain_= checkpoint *checkpoint_dst, static int make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *snapshot_dst,= virDomainSnapshotPtr snapshot_src) { - if (VIR_STRDUP(snapshot_dst->name, snapshot_src->name) < 0) - return -1; + snapshot_dst->name =3D g_strdup(snapshot_src->name); if (make_nonnull_domain(&snapshot_dst->dom, snapshot_src->domain) < 0)= { VIR_FREE(snapshot_dst->name); return -1; @@ -7699,8 +7654,7 @@ remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr= errors, goto error; =20 for (i =3D 0; i < nerrors; i++) { - if (VIR_STRDUP(val[i].disk, errors[i].disk) < 0) - goto error; + val[i].disk =3D g_strdup(errors[i].disk); val[i].error =3D errors[i].error; } =20 diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index c22b257197..83477243fc 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -219,10 +219,7 @@ static int remoteSplitURIScheme(virURIPtr uri, return -1; =20 if (p) { - if (VIR_STRDUP(*transport, p + 1) < 0) { - VIR_FREE(*driver); - return -1; - } + *transport =3D g_strdup(p + 1); =20 p =3D *transport; while (*p) { @@ -744,8 +741,7 @@ remoteConnectSupportsFeatureUnlocked(virConnectPtr conn, #define EXTRACT_URI_ARG_STR(ARG_NAME, ARG_VAR) \ if (STRCASEEQ(var->name, ARG_NAME)) { \ VIR_FREE(ARG_VAR); \ - if (VIR_STRDUP(ARG_VAR, var->value) < 0) \ - goto failed; \ + ARG_VAR =3D g_strdup(var->value); \ var->ignore =3D 1; \ continue; \ } @@ -826,8 +822,7 @@ remoteGetUNIXSocket(remoteDriverTransport transport, virAsprintf(&direct_daemon, "virt%sd", driver) < 0) return NULL; =20 - if (VIR_STRDUP(legacy_daemon, "libvirtd") < 0) - return NULL; + legacy_daemon =3D g_strdup("libvirtd"); =20 if (driver && !(direct_sock_name =3D remoteGetUNIXSocketHelper(transport, direct= _daemon, flags))) @@ -1011,20 +1006,15 @@ doRemoteOpen(virConnectPtr conn, if (virAsprintf(&port, "%d", conn->uri->port) < 0) goto failed; } else if (transport =3D=3D REMOTE_DRIVER_TRANSPORT_TLS) { - if (VIR_STRDUP(port, LIBVIRTD_TLS_PORT) < 0) - goto failed; + port =3D g_strdup(LIBVIRTD_TLS_PORT); } else if (transport =3D=3D REMOTE_DRIVER_TRANSPORT_TCP) { - if (VIR_STRDUP(port, LIBVIRTD_TCP_PORT) < 0) - goto failed; + port =3D g_strdup(LIBVIRTD_TCP_PORT); } /* Port not used for unix, ext., default for ssh */ =20 - if (VIR_STRDUP(priv->hostname, - conn->uri && conn->uri->server ? - conn->uri->server : "localhost") < 0) - goto failed; + priv->hostname =3D g_strdup(conn->uri && conn->uri->server ? conn->uri= ->server : "localhost"); =20 - if (conn->uri && VIR_STRDUP(username, conn->uri->user) < 0) - goto failed; + if (conn->uri) + username =3D g_strdup(conn->uri->user); =20 /* Get the variables from the query string. * Then we need to reconstruct the query string (because @@ -1070,8 +1060,7 @@ doRemoteOpen(virConnectPtr conn, (STREQ(conn->uri->scheme, "remote") || STRPREFIX(conn->uri->scheme, "remote+"))) { /* Allow remote serve to probe */ - if (VIR_STRDUP(name, "") < 0) - goto failed; + name =3D g_strdup(""); } else { virURI tmpuri =3D { .scheme =3D (char *)driver_str, @@ -1090,8 +1079,7 @@ doRemoteOpen(virConnectPtr conn, } } else { /* Probe URI server side */ - if (VIR_STRDUP(name, "") < 0) - goto failed; + name =3D g_strdup(""); } =20 if (conf && !mode_str && @@ -1934,8 +1922,7 @@ remoteDeserializeDomainDiskErrors(remote_domain_disk_= error *ret_errors_val, } =20 for (i =3D 0; i < ret_errors_len; i++) { - if (VIR_STRDUP(errors[i].disk, ret_errors_val[i].disk) < 0) - goto error; + errors[i].disk =3D g_strdup(ret_errors_val[i].disk); errors[i].error =3D ret_errors_val[i].error; } =20 @@ -4924,16 +4911,14 @@ remoteDomainBuildEventGraphicsHelper(virConnectPtr = conn, if (VIR_ALLOC(localAddr) < 0) goto error; localAddr->family =3D msg->local.family; - if (VIR_STRDUP(localAddr->service, msg->local.service) < 0 || - VIR_STRDUP(localAddr->node, msg->local.node) < 0) - goto error; + localAddr->service =3D g_strdup(msg->local.service); + localAddr->node =3D g_strdup(msg->local.node); =20 if (VIR_ALLOC(remoteAddr) < 0) goto error; remoteAddr->family =3D msg->remote.family; - if (VIR_STRDUP(remoteAddr->service, msg->remote.service) < 0 || - VIR_STRDUP(remoteAddr->node, msg->remote.node) < 0) - goto error; + remoteAddr->service =3D g_strdup(msg->remote.service); + remoteAddr->node =3D g_strdup(msg->remote.node); =20 if (VIR_ALLOC(subject) < 0) goto error; @@ -4941,9 +4926,8 @@ remoteDomainBuildEventGraphicsHelper(virConnectPtr co= nn, goto error; subject->nidentity =3D msg->subject.subject_len; for (i =3D 0; i < subject->nidentity; i++) { - if (VIR_STRDUP(subject->identities[i].type, msg->subject.subject_v= al[i].type) < 0 || - VIR_STRDUP(subject->identities[i].name, msg->subject.subject_v= al[i].name) < 0) - goto error; + subject->identities[i].type =3D g_strdup(msg->subject.subject_val[= i].type); + subject->identities[i].name =3D g_strdup(msg->subject.subject_val[= i].name); } =20 event =3D virDomainEventGraphicsNewFromDom(dom, @@ -6158,12 +6142,10 @@ remoteDomainQemuMonitorCommand(virDomainPtr domain,= const char *cmd, (xdrproc_t) xdr_qemu_domain_monitor_command_ret, (char *) &re= t) =3D=3D -1) goto done; =20 - if (VIR_STRDUP(*result, ret.result) < 0) - goto cleanup; + *result =3D g_strdup(ret.result); =20 rv =3D 0; =20 - cleanup: xdr_free((xdrproc_t) xdr_qemu_domain_monitor_command_ret, (char *) &re= t); =20 done: @@ -7658,45 +7640,35 @@ remoteSerializeDHCPLease(virNetworkDHCPLeasePtr lea= se_dst, remote_network_dhcp_l lease_dst->type =3D lease_src->type; lease_dst->prefix =3D lease_src->prefix; =20 - if (VIR_STRDUP(lease_dst->iface, lease_src->iface) < 0) - goto error; + lease_dst->iface =3D g_strdup(lease_src->iface); =20 - if (VIR_STRDUP(lease_dst->ipaddr, lease_src->ipaddr) < 0) - goto error; + lease_dst->ipaddr =3D g_strdup(lease_src->ipaddr); =20 if (lease_src->mac) { - if (VIR_STRDUP(lease_dst->mac, *lease_src->mac) < 0) - goto error; + lease_dst->mac =3D g_strdup(*lease_src->mac); } else { lease_src->mac =3D NULL; } =20 if (lease_src->iaid) { - if (VIR_STRDUP(lease_dst->iaid, *lease_src->iaid) < 0) - goto error; + lease_dst->iaid =3D g_strdup(*lease_src->iaid); } else { lease_src->iaid =3D NULL; } =20 if (lease_src->hostname) { - if (VIR_STRDUP(lease_dst->hostname, *lease_src->hostname) < 0) - goto error; + lease_dst->hostname =3D g_strdup(*lease_src->hostname); } else { lease_src->hostname =3D NULL; } =20 if (lease_src->clientid) { - if (VIR_STRDUP(lease_dst->clientid, *lease_src->clientid) < 0) - goto error; + lease_dst->clientid =3D g_strdup(*lease_src->clientid); } else { lease_src->clientid =3D NULL; } =20 return 0; - - error: - virNetworkDHCPLeaseFree(lease_dst); - return -1; } =20 =20 @@ -7953,14 +7925,11 @@ remoteDomainGetFSInfo(virDomainPtr dom, if (VIR_ALLOC(info_ret[i]) < 0) goto cleanup; =20 - if (VIR_STRDUP(info_ret[i]->mountpoint, src->mountpoint) < 0) - goto cleanup; + info_ret[i]->mountpoint =3D g_strdup(src->mountpoint); =20 - if (VIR_STRDUP(info_ret[i]->name, src->name) < 0) - goto cleanup; + info_ret[i]->name =3D g_strdup(src->name); =20 - if (VIR_STRDUP(info_ret[i]->fstype, src->fstype) < 0) - goto cleanup; + info_ret[i]->fstype =3D g_strdup(src->fstype); =20 len =3D src->dev_aliases.dev_aliases_len; info_ret[i]->ndevAlias =3D len; @@ -7968,11 +7937,8 @@ remoteDomainGetFSInfo(virDomainPtr dom, VIR_ALLOC_N(info_ret[i]->devAlias, len) < 0) goto cleanup; =20 - for (j =3D 0; j < len; j++) { - if (VIR_STRDUP(info_ret[i]->devAlias[j], - src->dev_aliases.dev_aliases_val[j]) < 0) - goto cleanup; - } + for (j =3D 0; j < len; j++) + info_ret[i]->devAlias[j] =3D g_strdup(src->dev_aliases.dev= _aliases_val[j]); } =20 *info =3D info_ret; @@ -8047,12 +8013,10 @@ remoteDomainInterfaceAddresses(virDomainPtr dom, =20 iface =3D ifaces_ret[i]; =20 - if (VIR_STRDUP(iface->name, iface_ret->name) < 0) - goto cleanup; + iface->name =3D g_strdup(iface_ret->name); =20 - if (iface_ret->hwaddr && - VIR_STRDUP(iface->hwaddr, *iface_ret->hwaddr) < 0) - goto cleanup; + if (iface_ret->hwaddr) + iface->hwaddr =3D g_strdup(*iface_ret->hwaddr); =20 if (iface_ret->addrs.addrs_len > REMOTE_DOMAIN_IP_ADDR_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -8072,8 +8036,7 @@ remoteDomainInterfaceAddresses(virDomainPtr dom, remote_domain_ip_addr *ip_addr_ret =3D &(iface_ret->addrs.addrs_val[j]); =20 - if (VIR_STRDUP(ip_addr->addr, ip_addr_ret->addr) < 0) - goto cleanup; + ip_addr->addr =3D g_strdup(ip_addr_ret->addr); =20 ip_addr->prefix =3D ip_addr_ret->prefix; ip_addr->type =3D ip_addr_ret->type; @@ -8170,8 +8133,7 @@ remoteDomainRename(virDomainPtr dom, const char *new_= name, unsigned int flags) remote_domain_rename_ret ret; char *tmp =3D NULL; =20 - if (VIR_STRDUP(tmp, new_name) < 0) - return -1; + tmp =3D g_strdup(new_name); =20 remoteDriverLock(priv); =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list