From nobody Fri May 3 21:00:11 2024 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=1601475409; cv=none; d=zohomail.com; s=zohoarc; b=PaWWBnxifW+bbUgfHu6eaM1kUBBabmpIjNSy5Bm/slzWNqMuM0DdkB55qzUc81/m14qI6+32PwH/FYXsLQrjW1laITvCUKq3BokZyh8fI1YkueZVDKqvucogbaHc9/XKMppQFIQCUkT+yaarS4GRgUpcUFjYVkVCvuL4WnzkBJ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601475409; 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=FEAlvH97tF4stYKCEJS51jUvaspakhz9ILHXXOSp2o4=; b=eMv0DefKPMJMweUbMKeGkrgDWUOfjnzyjBp8Z+h5qtwlAC10noW+XwEfWpM+YN0AIJSXHEa6tC/a8atV6cf3MalrKD9vXyU1djsEKjkEvivwCU59xAl8UwpC2VEdFPJPG8fkHidaULao6w4Mxo2zZZOgrinmTjQWtejGc6ezAIc= 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 1601475409749657.015331262096; Wed, 30 Sep 2020 07:16:49 -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-170-17xxLV3TPQ-ykkAAyBNY0w-1; Wed, 30 Sep 2020 10:16:46 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0BFF8186DD31; Wed, 30 Sep 2020 14:16:38 +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 699C05D9F3; Wed, 30 Sep 2020 14:16:37 +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 6D8C3183D021; Wed, 30 Sep 2020 14:16:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08UEB2ZS017610 for ; Wed, 30 Sep 2020 10:11:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0EFCF6198B; Wed, 30 Sep 2020 14:11:02 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BE4E60C07 for ; Wed, 30 Sep 2020 14:11:01 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601475408; 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=FEAlvH97tF4stYKCEJS51jUvaspakhz9ILHXXOSp2o4=; b=JZ9NXuuwwZMnL+Mi+tXH+YSFG3p8368WGlLT8AerhIKtXn2yCPQppE/VkFWak/lChHxI4F rqya+WXOHVHNe71ZyraMaJZsLhWtnsjqT1gkN1bqiZsXPqEtYGr5qXnpedCPnrKIdnQv2Z vLGQ2FVCgJLH070iidsRyp2aZYUEdhU= X-MC-Unique: 17xxLV3TPQ-ykkAAyBNY0w-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/3] logging: use g_new0 instead of VIR_ALLOC Date: Wed, 30 Sep 2020 16:10:53 +0200 Message-Id: <8d6b2a51ecfa0ec87f4fdc5ad8af67d81d697116.1601475025.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.14 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: J=C3=A1n Tomko Reviewed-by: Michal Privoznik --- src/logging/log_daemon.c | 9 +++------ src/logging/log_daemon_config.c | 3 +-- src/logging/log_handler.c | 9 +++------ src/logging/log_manager.c | 3 +-- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index 0649a70c9d..be93c63eb5 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -116,8 +116,7 @@ virLogDaemonNew(virLogDaemonConfigPtr config, bool priv= ileged) virLogDaemonPtr logd; virNetServerPtr srv =3D NULL; =20 - if (VIR_ALLOC(logd) < 0) - return NULL; + logd =3D g_new0(virLogDaemon, 1); =20 g_mutex_init(&logd->lock); =20 @@ -214,8 +213,7 @@ virLogDaemonNewPostExecRestart(virJSONValuePtr object, = bool privileged, virJSONValuePtr child; const char *serverNames[] =3D { "virtlogd" }; =20 - if (VIR_ALLOC(logd) < 0) - return NULL; + logd =3D g_new0(virLogDaemon, 1); =20 g_mutex_init(&logd->lock); =20 @@ -330,8 +328,7 @@ virLogDaemonClientNew(virNetServerClientPtr client, unsigned long long timestamp; bool privileged =3D opaque !=3D NULL; =20 - if (VIR_ALLOC(priv) < 0) - return NULL; + priv =3D g_new0(virLogDaemonClient, 1); =20 g_mutex_init(&priv->lock); =20 diff --git a/src/logging/log_daemon_config.c b/src/logging/log_daemon_confi= g.c index 97f2de90a6..5577991b13 100644 --- a/src/logging/log_daemon_config.c +++ b/src/logging/log_daemon_config.c @@ -58,8 +58,7 @@ virLogDaemonConfigNew(bool privileged G_GNUC_UNUSED) { virLogDaemonConfigPtr data; =20 - if (VIR_ALLOC(data) < 0) - return NULL; + data =3D g_new0(virLogDaemonConfig, 1); =20 data->max_clients =3D 1024; data->admin_max_clients =3D 5000; diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c index 87748d96d1..d47009d686 100644 --- a/src/logging/log_handler.c +++ b/src/logging/log_handler.c @@ -221,8 +221,7 @@ virLogHandlerLogFilePostExecRestart(virLogHandlerPtr ha= ndler, const char *domuuid; const char *tmp; =20 - if (VIR_ALLOC(file) < 0) - return NULL; + file =3D g_new0(virLogHandlerLogFile, 1); =20 handler->inhibitor(true, handler->opaque); =20 @@ -389,8 +388,7 @@ virLogHandlerDomainOpenLogFile(virLogHandlerPtr handler, if (virPipe(pipefd) < 0) goto error; =20 - if (VIR_ALLOC(file) < 0) - goto error; + file =3D g_new0(virLogHandlerLogFile, 1); =20 file->watch =3D -1; file->pipefd =3D pipefd[0]; @@ -537,8 +535,7 @@ virLogHandlerDomainReadLogFile(virLogHandlerPtr handler, if (virRotatingFileReaderSeek(file, inode, offset) < 0) goto error; =20 - if (VIR_ALLOC_N(data, maxlen + 1) < 0) - goto error; + data =3D g_new0(char, maxlen + 1); =20 got =3D virRotatingFileReaderConsume(file, data, maxlen); if (got < 0) diff --git a/src/logging/log_manager.c b/src/logging/log_manager.c index fd7c2922b3..57be340a2d 100644 --- a/src/logging/log_manager.c +++ b/src/logging/log_manager.c @@ -113,8 +113,7 @@ virLogManagerNew(bool privileged) { virLogManagerPtr mgr; =20 - if (VIR_ALLOC(mgr) < 0) - goto error; + mgr =3D g_new0(virLogManager, 1); =20 if (!(mgr->client =3D virLogManagerConnect(privileged, &mgr->program))) goto error; --=20 2.26.2 From nobody Fri May 3 21:00:11 2024 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=1601475419; cv=none; d=zohomail.com; s=zohoarc; b=BpmAVVLynEhF59vrANb1pM4dUP9m912P0vuTLeovfsz+g08zUuv7N8YJgJDu993ZEw3C8061ieYgUtsJbbGV9nFfcQBO1pG+AE/tM0zq0ZMnPoEYLi8NIqRcmkhs+3WKv4bCXsJX0NS6nfhhsRhgJ25ePEAS1L81S/x5hQ/8KbY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601475419; 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=U5W9T8IxFJrGyBMukxiBQX4O3inF5SbJ+22kGa40swY=; b=Y6oMsEF5o7EukFOhqLtL/FqzITyfal/yGqdz7hD/u/wXb7I75UBva2u2Hre9hjaEeF4m+lNulME2/DwIH46XdG5Hn1MNYKU0xZnYo8jI+vfP17vXqz6siqty5m9hn95DKVilsLqbSxbQ2345kP6ppebF+eM7T7KyPOlf18wRqos= 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 1601475419764563.0672261621355; Wed, 30 Sep 2020 07:16:59 -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-583-qq3_a8-jNkiDjyMC6wa61A-1; Wed, 30 Sep 2020 10:16:55 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B947C186DD2A; Wed, 30 Sep 2020 14:16:48 +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 9757E5DA76; Wed, 30 Sep 2020 14:16:48 +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 270CD183D025; Wed, 30 Sep 2020 14:16:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08UEB21K017619 for ; Wed, 30 Sep 2020 10:11:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id D35C16198B; Wed, 30 Sep 2020 14:11:02 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5BEA860C07 for ; Wed, 30 Sep 2020 14:11:02 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601475418; 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=U5W9T8IxFJrGyBMukxiBQX4O3inF5SbJ+22kGa40swY=; b=d2oB/J8vBySF8Y78J7uhsmRgaqy5pLAl4IUh7LhluFvUCI87E2pBWrpoUYTJm9P1U6LdV6 xpvamZ6cQJstY5Q0lOxeum6iBbKEpzwtxep6r1dZAfBiqwJetrJvjPxA/BpyDZlkSubGsY hE3bCUsAkWuWUu6ZN1epoyPCdjednk8= X-MC-Unique: qq3_a8-jNkiDjyMC6wa61A-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/3] gendispatch: use g_new0 instead of VIR_ALLOC Date: Wed, 30 Sep 2020 16:10:54 +0200 Message-Id: <557e77c0a9f1346aef9f6988f8e9261fa65362f7.1601475025.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.14 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Take the easy way out and use typeof, because my life is too short to spend it reading gendispatch.pl. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Michal Privoznik --- src/rpc/gendispatch.pl | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index 0b2ae59910..91575f4d34 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -797,8 +797,7 @@ elsif ($mode eq "server") { push(@free_list, " VIR_FREE($1);"); push(@free_list_on_error, "VIR_FREE($1_p);"); push(@prepare_ret_list, - "if (VIR_ALLOC($1_p) < 0)\n" . - " goto cleanup;\n" . + "$1_p =3D g_new0(char *, 1);\n" . "\n" . " *$1_p =3D g_strdup($1);\n"); =20 @@ -1126,9 +1125,9 @@ elsif ($mode eq "server") { =20 if ($single_ret_as_list) { print " /* Allocate return buffer. */\n"; - print " if (VIR_ALLOC_N(ret->$single_ret_list_name.${si= ngle_ret_list_name}_val," . - " args->$single_ret_list_max_var) < 0)\n"; - print " goto cleanup;\n"; + print " ret->$single_ret_list_name.${single_ret_list_na= me}_val =3D\n"; + print " g_new0(typeof(*ret->$single_ret_list_name.$= {single_ret_list_name}_val), " . + "args->$single_ret_list_max_var); \n"; print "\n"; } =20 @@ -1188,8 +1187,8 @@ elsif ($mode eq "server") { print " }\n"; print "\n"; print " if (result && nresults) {\n"; - print " if (VIR_ALLOC_N(ret->$single_ret_list_name.${si= ngle_ret_list_name}_val, nresults) < 0)\n"; - print " goto cleanup;\n"; + print " ret->$single_ret_list_name.${single_ret_list_na= me}_val =3D\n"; + print " g_new0(typeof(*ret->$single_ret_list_name.$= {single_ret_list_name}_val), nresults);\n"; print "\n"; print " ret->$single_ret_list_name.${single_ret_list_na= me}_len =3D nresults;\n"; if ($modern_ret_is_nested) { @@ -1950,8 +1949,7 @@ elsif ($mode eq "client") { $priv_src =3D~ s/->conn//; } print " if (result) {\n"; - print " if (VIR_ALLOC_N(tmp_results, ret.$single_ret_li= st_name.${single_ret_list_name}_len + 1) < 0)\n"; - print " goto cleanup;\n"; + print " tmp_results =3D g_new0(typeof(*tmp_results), re= t.$single_ret_list_name.${single_ret_list_name}_len + 1);\n"; print "\n"; print " for (i =3D 0; i < ret.$single_ret_list_name.${s= ingle_ret_list_name}_len; i++) {\n"; print " tmp_results[i] =3D get_nonnull_$modern_ret_= struct_name($priv_src, ret.$single_ret_list_name.${single_ret_list_name}_va= l[i]);\n"; --=20 2.26.2 From nobody Fri May 3 21:00:11 2024 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=1601475423; cv=none; d=zohomail.com; s=zohoarc; b=VqzYfaQECjQzsRb/KurOKAvE6FTEPzQGxgLaYDYoGwyVTjTP1mXvF1hh+1xhmDGvpFpLOrZNmiSz8MEpDS6oRqAYlsyJaOLNtZoSTLtV2J7XkMAIiSW452itZUdS3ZG5fpiVCsCWe3ZM9QeqAICW9rSlXpJAS3aLkH0nukAm1k4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601475423; 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=l/eiA1eyjwjZIityu/1nMdq+AIgl0JyvmM85JqHuOT0=; b=lqUol4vRqKBABjTqc9/cagg+RFlnqEogflI4pEYZML0Z0IfsEGPbvAvwyL6cvTfsf/7o+AjdJ/gp7qT6KOVe5nXJMtUZs+BCN+z5H5T4XYB3ysrRcDDGoDXau0Cbhw9FS8RCw2gykbipha+ZjOWTrujOisnD822YzLmPx9mU5eE= 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 1601475423866736.7659442775018; Wed, 30 Sep 2020 07:17:03 -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-331-FeNohPGfMYO5kGG-_d8K1A-1; Wed, 30 Sep 2020 10:16:58 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 01BFC1015CB7; Wed, 30 Sep 2020 14:16:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D206081C56; Wed, 30 Sep 2020 14:16:51 +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 9873544A5D; Wed, 30 Sep 2020 14:16:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08UEB5JO017637 for ; Wed, 30 Sep 2020 10:11:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9E3D260C07; Wed, 30 Sep 2020 14:11:05 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24E6B65F5E for ; Wed, 30 Sep 2020 14:11:03 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601475422; 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=l/eiA1eyjwjZIityu/1nMdq+AIgl0JyvmM85JqHuOT0=; b=VrJdUN63cCnHPX4ZRLXNnx6L7TZFLrmIYjy2+YaUX1vx/tl19zv38AJp6aeStYjOhn7MZM XQV/WECfGYmv59D0eEZdml5c0OiJzUUACrxa0/0ZQmLIYk0vNKqR/wx64ZtcVEc00D3Lll o0pd2Zhgm1ZfRHQojsuv8YXRb8PuDwg= X-MC-Unique: FeNohPGfMYO5kGG-_d8K1A-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 3/3] rpc: use g_new0 instead of VIR_ALLOC Date: Wed, 30 Sep 2020 16:10:55 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.13 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: J=C3=A1n Tomko Reviewed-by: Michal Privoznik --- src/rpc/virnetclient.c | 6 ++---- src/rpc/virnetclientprogram.c | 10 ++++------ src/rpc/virnetdaemon.c | 3 +-- src/rpc/virnetlibsshsession.c | 3 +-- src/rpc/virnetmessage.c | 23 +++++++++++++++-------- src/rpc/virnetserver.c | 3 +-- src/rpc/virnetserverclient.c | 24 ++++++------------------ src/rpc/virnetserverprogram.c | 6 ++---- src/rpc/virnetserverservice.c | 9 +++------ src/rpc/virnetsocket.c | 3 +-- src/rpc/virnetsshsession.c | 8 ++------ src/rpc/virnettlscontext.c | 4 +--- 12 files changed, 39 insertions(+), 63 deletions(-) diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 8c7c7a0f0a..c6591ecdfc 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -1435,8 +1435,7 @@ virNetClientIOReadMessage(virNetClientPtr client) /* Start by reading length word */ if (client->msg.bufferLength =3D=3D 0) { client->msg.bufferLength =3D 4; - if (VIR_ALLOC_N(client->msg.buffer, client->msg.bufferLength) < 0) - return -ENOMEM; + client->msg.buffer =3D g_new0(char, client->msg.bufferLength); } =20 wantData =3D client->msg.bufferLength - client->msg.bufferOffset; @@ -2107,8 +2106,7 @@ virNetClientCallNew(virNetMessagePtr msg, goto error; } =20 - if (VIR_ALLOC(call) < 0) - goto error; + call =3D g_new0(virNetClientCall, 1); =20 if (virCondInit(&call->cond) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/src/rpc/virnetclientprogram.c b/src/rpc/virnetclientprogram.c index 4d1a2bc28b..0269f3e6dd 100644 --- a/src/rpc/virnetclientprogram.c +++ b/src/rpc/virnetclientprogram.c @@ -247,8 +247,7 @@ int virNetClientProgramDispatch(virNetClientProgramPtr = prog, return -1; } =20 - if (VIR_ALLOC_N(evdata, event->msg_len) < 0) - return -1; + evdata =3D g_new0(char, event->msg_len); =20 if (virNetMessageDecodePayload(msg, event->msg_filter, evdata) < 0) goto cleanup; @@ -291,8 +290,7 @@ int virNetClientProgramCall(virNetClientProgramPtr prog, msg->header.type =3D noutfds ? VIR_NET_CALL_WITH_FDS : VIR_NET_CALL; msg->header.serial =3D serial; msg->header.proc =3D proc; - if (VIR_ALLOC_N(msg->fds, noutfds) < 0) - goto error; + msg->fds =3D g_new0(int, noutfds); msg->nfds =3D noutfds; for (i =3D 0; i < msg->nfds; i++) msg->fds[i] =3D -1; @@ -351,8 +349,8 @@ int virNetClientProgramCall(virNetClientProgramPtr prog, case VIR_NET_OK: if (infds && ninfds) { *ninfds =3D msg->nfds; - if (VIR_ALLOC_N(*infds, *ninfds) < 0) - goto error; + *infds =3D g_new0(int, *ninfds); + for (i =3D 0; i < *ninfds; i++) (*infds)[i] =3D -1; for (i =3D 0; i < *ninfds; i++) { diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index 2e01244f74..37a5662e04 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -673,8 +673,7 @@ virNetDaemonAddSignalHandler(virNetDaemonPtr dmn, if (VIR_EXPAND_N(dmn->signals, dmn->nsignals, 1) < 0) goto error; =20 - if (VIR_ALLOC(sigdata) < 0) - goto error; + sigdata =3D g_new0(virNetDaemonSignal, 1); =20 sigdata->signum =3D signum; sigdata->func =3D func; diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c index 81646a360a..959a16a6a9 100644 --- a/src/rpc/virnetlibsshsession.c +++ b/src/rpc/virnetlibsshsession.c @@ -185,8 +185,7 @@ virNetLibsshSessionAuthMethodNew(virNetLibsshSessionPtr= sess) { virNetLibsshAuthMethodPtr auth; =20 - if (VIR_ALLOC(auth) < 0) - goto error; + auth =3D g_new0(virNetLibsshAuthMethod, 1); =20 if (VIR_EXPAND_N(sess->auths, sess->nauths, 1) < 0) goto error; diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c index 6423ce67a3..b728e73f4f 100644 --- a/src/rpc/virnetmessage.c +++ b/src/rpc/virnetmessage.c @@ -38,8 +38,7 @@ virNetMessagePtr virNetMessageNew(bool tracked) { virNetMessagePtr msg; =20 - if (VIR_ALLOC(msg) < 0) - return NULL; + msg =3D g_new0(virNetMessage, 1); =20 msg->tracked =3D tracked; VIR_DEBUG("msg=3D%p tracked=3D%d", msg, tracked); @@ -328,8 +327,8 @@ int virNetMessageDecodeNumFDs(virNetMessagePtr msg) =20 if (msg->nfds =3D=3D 0) { msg->nfds =3D numFDs; - if (VIR_ALLOC_N(msg->fds, msg->nfds) < 0) - goto cleanup; + msg->fds =3D g_new0(int, msg->nfds); + for (i =3D 0; i < msg->nfds; i++) msg->fds[i] =3D -1; } @@ -525,15 +524,23 @@ void virNetMessageSaveError(virNetMessageErrorPtr rer= r) if (verr) { rerr->code =3D verr->code; rerr->domain =3D verr->domain; - if (verr->message && VIR_ALLOC(rerr->message) =3D=3D 0) + if (verr->message) { + rerr->message =3D g_new0(char *, 1); *rerr->message =3D g_strdup(verr->message); + } rerr->level =3D verr->level; - if (verr->str1 && VIR_ALLOC(rerr->str1) =3D=3D 0) + if (verr->str1) { + rerr->str1 =3D g_new0(char *, 1); *rerr->str1 =3D g_strdup(verr->str1); - if (verr->str2 && VIR_ALLOC(rerr->str2) =3D=3D 0) + } + if (verr->str2) { + rerr->str2 =3D g_new0(char *, 1); *rerr->str2 =3D g_strdup(verr->str2); - if (verr->str3 && VIR_ALLOC(rerr->str3) =3D=3D 0) + } + if (verr->str3) { + rerr->str3 =3D g_new0(char *, 1); *rerr->str3 =3D g_strdup(verr->str3); + } rerr->int1 =3D verr->int1; rerr->int2 =3D verr->int2; } else { diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index 79ea9f68a0..fa63acbb09 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -211,8 +211,7 @@ virNetServerDispatchNewMessage(virNetServerClientPtr cl= ient, if (virThreadPoolGetMaxWorkers(srv->workers) > 0) { virNetServerJobPtr job; =20 - if (VIR_ALLOC(job) < 0) - goto error; + job =3D g_new0(virNetServerJob, 1); =20 job->client =3D virObjectRef(client); job->msg =3D msg; diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c index 756adcbb4f..4d01e87e21 100644 --- a/src/rpc/virnetserverclient.c +++ b/src/rpc/virnetserverclient.c @@ -240,8 +240,7 @@ int virNetServerClientAddFilter(virNetServerClientPtr c= lient, virNetServerClientFilterPtr *place; int ret; =20 - if (VIR_ALLOC(filter) < 0) - return -1; + filter =3D g_new0(virNetServerClientFilter, 1); =20 virObjectLock(client); =20 @@ -311,10 +310,7 @@ virNetServerClientCheckAccess(virNetServerClientPtr cl= ient) * (NB. The '\1' byte is sent in an encrypted record). */ confirm->bufferLength =3D 1; - if (VIR_ALLOC_N(confirm->buffer, confirm->bufferLength) < 0) { - virNetMessageFree(confirm); - return -1; - } + confirm->buffer =3D g_new0(char, confirm->bufferLength); confirm->bufferOffset =3D 0; confirm->buffer[0] =3D '\1'; =20 @@ -414,8 +410,7 @@ virNetServerClientNewInternal(unsigned long long id, if (!(client->rx =3D virNetMessageNew(true))) goto error; client->rx->bufferLength =3D VIR_NET_MESSAGE_LEN_MAX; - if (VIR_ALLOC_N(client->rx->buffer, client->rx->bufferLength) < 0) - goto error; + client->rx->buffer =3D g_new0(char, client->rx->bufferLength); client->nrequests =3D 1; =20 PROBE(RPC_SERVER_CLIENT_NEW, @@ -1306,12 +1301,8 @@ static virNetMessagePtr virNetServerClientDispatchRe= ad(virNetServerClientPtr cli client->wantClose =3D true; } else { client->rx->bufferLength =3D VIR_NET_MESSAGE_LEN_MAX; - if (VIR_ALLOC_N(client->rx->buffer, - client->rx->bufferLength) < 0) { - client->wantClose =3D true; - } else { - client->nrequests++; - } + client->rx->buffer =3D g_new0(char, client->rx->bufferLeng= th); + client->nrequests++; } } virNetServerClientUpdateEvent(client); @@ -1411,10 +1402,7 @@ virNetServerClientDispatchWrite(virNetServerClientPt= r client) /* Ready to recv more messages */ virNetMessageClear(msg); msg->bufferLength =3D VIR_NET_MESSAGE_LEN_MAX; - if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0) { - virNetMessageFree(msg); - return; - } + msg->buffer =3D g_new0(char, msg->bufferLength); client->rx =3D msg; msg =3D NULL; client->nrequests++; diff --git a/src/rpc/virnetserverprogram.c b/src/rpc/virnetserverprogram.c index f8d7fe85ed..3884d62fd8 100644 --- a/src/rpc/virnetserverprogram.c +++ b/src/rpc/virnetserverprogram.c @@ -403,10 +403,8 @@ virNetServerProgramDispatchCall(virNetServerProgramPtr= prog, goto error; } =20 - if (VIR_ALLOC_N(arg, dispatcher->arg_len) < 0) - goto error; - if (VIR_ALLOC_N(ret, dispatcher->ret_len) < 0) - goto error; + arg =3D g_new0(char, dispatcher->arg_len); + ret =3D g_new0(char, dispatcher->ret_len); =20 if (virNetMessageDecodePayload(msg, dispatcher->arg_filter, arg) < 0) goto error; diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index e4165eacb7..317cacf25b 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -106,8 +106,7 @@ virNetServerServiceNewSocket(virNetSocketPtr *socks, if (!(svc =3D virObjectNew(virNetServerServiceClass))) return NULL; =20 - if (VIR_ALLOC_N(svc->socks, nsocks) < 0) - goto error; + svc->socks =3D g_new0(virNetSocketPtr, nsocks); svc->nsocks =3D nsocks; for (i =3D 0; i < svc->nsocks; i++) { svc->socks[i] =3D socks[i]; @@ -230,8 +229,7 @@ virNetServerServicePtr virNetServerServiceNewFDs(int *f= ds, virNetSocketPtr *socks; size_t i; =20 - if (VIR_ALLOC_N(socks, nfds) < 0) - goto cleanup; + socks =3D g_new0(virNetSocketPtr, nfds); =20 for (i =3D 0; i < nfds; i++) { if (virNetSocketNewListenFD(fds[i], @@ -301,8 +299,7 @@ virNetServerServicePtr virNetServerServiceNewPostExecRe= start(virJSONValuePtr obj } =20 n =3D virJSONValueArraySize(socks); - if (VIR_ALLOC_N(svc->socks, n) < 0) - goto error; + svc->socks =3D g_new0(virNetSocketPtr, n); svc->nsocks =3D n; =20 for (i =3D 0; i < svc->nsocks; i++) { diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index f79a638775..fc9dd023da 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -1876,8 +1876,7 @@ static ssize_t virNetSocketReadSASL(virNetSocketPtr s= ock, char *buf, size_t len) if (sock->saslDecoded =3D=3D NULL) { ssize_t encodedLen =3D virNetSASLSessionGetMaxBufSize(sock->saslSe= ssion); char *encoded; - if (VIR_ALLOC_N(encoded, encodedLen) < 0) - return -1; + encoded =3D g_new0(char, encodedLen); encodedLen =3D virNetSocketReadWire(sock, encoded, encodedLen); =20 if (encodedLen <=3D 0) { diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index bb6e137939..4b56363fa0 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -173,8 +173,7 @@ virNetSSHSessionAuthMethodNew(virNetSSHSessionPtr sess) { virNetSSHAuthMethodPtr auth; =20 - if (VIR_ALLOC(auth) < 0) - goto error; + auth =3D g_new0(virNetSSHAuthMethod, 1); =20 if (VIR_EXPAND_N(sess->auths, sess->nauths, 1) < 0) goto error; @@ -223,10 +222,7 @@ virNetSSHKbIntCb(const char *name G_GNUC_UNUSED, return; } =20 - if (VIR_ALLOC_N(askcred, num_prompts) < 0) { - priv->authCbErr =3D VIR_NET_SSH_AUTHCB_OOM; - return; - } + askcred =3D g_new0(virConnectCredential, num_prompts); =20 /* fill data structures for auth callback */ for (i =3D 0; i < num_prompts; i++) { diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c index 37564db14e..84f7e63e4d 100644 --- a/src/rpc/virnettlscontext.c +++ b/src/rpc/virnettlscontext.c @@ -299,9 +299,7 @@ static int virNetTLSContextCheckCertKeyPurpose(gnutls_x= 509_crt_t cert, return -1; } =20 - if (VIR_ALLOC_N(buffer, size) < 0) - return -1; - + buffer =3D g_new0(char, size); status =3D gnutls_x509_crt_get_key_purpose_oid(cert, i, buffer, &s= ize, &purposeCritical); if (status < 0) { VIR_FREE(buffer); --=20 2.26.2