From nobody Tue Oct 22 22:21:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1729607455; cv=none; d=zohomail.com; s=zohoarc; b=lFE1aHf0wPlAjXL6RMBQywb+7aTW5LAA5XUIXFCB0z0Emy9Bf3YKbfCZ38GjN8AcjMBAxnso1ElzrvMeaiNSeWXgpoH5vASTV1jrchJm8DaRuRQuQVcKW2TYcSOUP/rIX0qPO4avSNMX8cST+ZBQrx0eJUmWNo9gO/ZTmTuexk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729607455; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=34PkQkzS2fJKjA97jCvEOEfq09+BKhcwhQ4YHpj/pVU=; b=cNYywteSQftn3GkrallTGI9Kl7ZbnsfZ4ogRiukiZaiIX0H1n+a2SLGiuvzD6CKDI2fqpaEw9OdkEL9YPezEvpgUgBYFr8xlXopcPeWs9G7yuxPDL0PwCwZV5bmvYwAgKyRMGYOigpkYpQe/+Vn5zS1N5I/6Ukn8ku7ZlTR42xA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729607455471137.76409931268302; Tue, 22 Oct 2024 07:30:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3Fty-0001Xb-AQ; Tue, 22 Oct 2024 10:30:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3Fti-0001Om-FA for qemu-devel@nongnu.org; Tue, 22 Oct 2024 10:30:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3Ftg-0007EN-O8 for qemu-devel@nongnu.org; Tue, 22 Oct 2024 10:30:09 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-OM0OjuzlPReio9LBApKOhQ-1; Tue, 22 Oct 2024 10:30:04 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9788F19560BE; Tue, 22 Oct 2024 14:30:03 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.116.80]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B3B001955E84; Tue, 22 Oct 2024 14:29:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729607407; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=34PkQkzS2fJKjA97jCvEOEfq09+BKhcwhQ4YHpj/pVU=; b=eUwHvAruEZxZPg2OszD6TE8IGE4XZ6/EQ/UnrrUf69qaSejNKPqPkQVtBFjLeeir5W3iG+ 0VnbAsBy9TeHn0WKAJmwC/bCigB38s8mc+J00snNbHXlT4jCiEkPGPZgpvzsyfIOFZCAzO Nshzwy909doX55x3jnOSLkts9Wx6GKc= X-MC-Unique: OM0OjuzlPReio9LBApKOhQ-1 From: Dehan Meng To: qemu-devel@nongnu.org Cc: demeng@redhat.com, kkostiuk@redhat.com, michael.roth@amd.com, peter.maydell@linaro.org, berrange@redhat.com Subject: [PATCH v4 1/5] qemu-ga: 'Null' check for mandatory parameters Date: Tue, 22 Oct 2024 22:29:44 +0800 Message-Id: <20241022142948.531325-2-demeng@redhat.com> In-Reply-To: <20241022142948.531325-1-demeng@redhat.com> References: <20241022142948.531325-1-demeng@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=demeng@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.519, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1729607456687116600 Content-Type: text/plain; charset="utf-8" sscanf return values are checked and add 'Null' check for mandatory parameters. Signed-off-by: Dehan Meng --- qga/commands-linux.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/qga/commands-linux.c b/qga/commands-linux.c index 51d5e3d927..f0e9cdd27c 100644 --- a/qga/commands-linux.c +++ b/qga/commands-linux.c @@ -2103,7 +2103,9 @@ static char *hexToIPAddress(const void *hexValue, int= is_ipv6) int i; =20 for (i =3D 0; i < 16; i++) { - sscanf(&hexStr[i * 2], "%02hhx", &in6.s6_addr[i]); + if (sscanf(&hex_str[i * 2], "%02hhx", &in6.s6_addr[i]) !=3D 1)= { + return NULL; + } } inet_ntop(AF_INET6, &in6, addr, INET6_ADDRSTRLEN); =20 @@ -2164,6 +2166,10 @@ GuestNetworkRouteList *qmp_guest_network_get_route(E= rror **errp) networkroute =3D route; networkroute->iface =3D g_strdup(Iface); networkroute->destination =3D hexToIPAddress(Destination, = 1); + if (networkroute->destination =3D=3D NULL) { + g_free(route); + continue; + } networkroute->metric =3D Metric; networkroute->source =3D hexToIPAddress(Source, 1); networkroute->desprefixlen =3D g_strdup_printf( @@ -2195,6 +2201,10 @@ GuestNetworkRouteList *qmp_guest_network_get_route(E= rror **errp) networkroute =3D route; networkroute->iface =3D g_strdup(Iface); networkroute->destination =3D hexToIPAddress(&Destination,= 0); + if (networkroute->destination =3D=3D NULL) { + g_free(route); + continue; + } networkroute->gateway =3D hexToIPAddress(&Gateway, 0); networkroute->mask =3D hexToIPAddress(&Mask, 0); networkroute->metric =3D Metric; --=20 2.40.1 From nobody Tue Oct 22 22:21:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1729607454; cv=none; d=zohomail.com; s=zohoarc; b=MiIr0587ZCk69R8WuAa78dd76rks0uVRQHKXZgoUlYgLxdm6IYWBAmnVwuRn+vzTljqHYcmzLLNjoNgJZPna1DJRDjLO0726+oyhjCjJG0qXsxkdIVbVkoiZIVeJi94+HNM+MZBU4sw+solOhnqDuxVyVXhURgEVhCVTVIKbAOU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729607454; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=89BuzVL2Ofdj6f7IOw3BkvNQfFJUf/0FqCtxr/n1RD0=; b=cKhfH8fhW+DID9o50qYHHa17SVUIt+SZNQs0Vg6XNxES0R+W5KQuiW2drxwAPqMOcFySWXivSVB3Rln5Yu8Zz2P0J/73jVXsn/EqvMSWE9O4likdm06DcFyXe0CUibO11mvAXwA+V3aIwYKxJFUstKBEkaQhyp+XI4hM3Y//v7k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729607454267543.8576359644061; Tue, 22 Oct 2024 07:30:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3FuJ-0001cL-So; Tue, 22 Oct 2024 10:30:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3Ftm-0001RY-89 for qemu-devel@nongnu.org; Tue, 22 Oct 2024 10:30:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3Ftk-0007F2-TS for qemu-devel@nongnu.org; Tue, 22 Oct 2024 10:30:14 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-166-XZSS0MzbNtGiW8gM8BCIRg-1; Tue, 22 Oct 2024 10:30:10 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 01C3919560AA; Tue, 22 Oct 2024 14:30:09 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.116.80]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 65B8E19560AE; Tue, 22 Oct 2024 14:30:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729607412; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=89BuzVL2Ofdj6f7IOw3BkvNQfFJUf/0FqCtxr/n1RD0=; b=fLyCQPS6K8AJ4YDsSFSDogLxF3btW/bGKz2FOWQ+6bVY8wjftq2F9NokHLFP3s6Q1kzm6s emoBoFmpenmn0x4dfIi8LX99jLJkyDsln5NXrq1rZJ743DY8hY441Vx2wnhhImtx1Pa0rC CevccuUC7T0OakWV3kPitH9bRXW7cCQ= X-MC-Unique: XZSS0MzbNtGiW8gM8BCIRg-1 From: Dehan Meng To: qemu-devel@nongnu.org Cc: demeng@redhat.com, kkostiuk@redhat.com, michael.roth@amd.com, peter.maydell@linaro.org, berrange@redhat.com Subject: [PATCH v4 2/5] qemu-ga: Initialize correctly so getline works properly Date: Tue, 22 Oct 2024 22:29:45 +0800 Message-Id: <20241022142948.531325-3-demeng@redhat.com> In-Reply-To: <20241022142948.531325-1-demeng@redhat.com> References: <20241022142948.531325-1-demeng@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=demeng@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.519, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1729607454694116600 Content-Type: text/plain; charset="utf-8" Proper initialization of param 'size_t n' to '0' for getline to function correctly. Signed-off-by: Dehan Meng --- qga/commands-linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qga/commands-linux.c b/qga/commands-linux.c index f0e9cdd27c..32bf1b8ce7 100644 --- a/qga/commands-linux.c +++ b/qga/commands-linux.c @@ -2126,7 +2126,7 @@ GuestNetworkRouteList *qmp_guest_network_get_route(Er= ror **errp) GuestNetworkRouteList *head =3D NULL, **tail =3D &head; const char *routeFiles[] =3D {"/proc/net/route", "/proc/net/ipv6_route= "}; FILE *fp; - size_t n; + size_t n =3D 0; char *line =3D NULL; int firstLine; int is_ipv6; --=20 2.40.1 From nobody Tue Oct 22 22:21:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1729607465; cv=none; d=zohomail.com; s=zohoarc; b=LcWJss1DTzrloHqpG8prfRPfixHThKOOkuYKr5vd7UNK69Bh7x7eNBI14MFdXAkLMbYxYo7BUb/uaachgjnPTUZfTSOBTXRj9kGo3dVCZcskISX5k8zVuMeMUT/dk7CxpxduL7Rq0JT1YFH9Rw8A70WAE3/ZLAedBxqH11UV/FA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729607465; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=S70GhYB7laEL2fnTCNmkV4yqr3u8YRvyEUuIY22drcU=; b=SznNdfrt14wKg51XnUkcfbPtAW6TJYNmKtOk9g8xk14E2fb2X29xzMg/0qn0KX4Wcd1g2TQvPcl8bGssnPPg11BFrV1UBAzTZ8LgsQNHHuMGq+f7PeobT2PC4g5n9iwPFTmxOY9rwk/VDMxgkVx7feTMyPQHKQoyJX8nL+dYtWM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729607465960320.5606698522372; Tue, 22 Oct 2024 07:31:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3FuO-0001oB-4Q; Tue, 22 Oct 2024 10:30:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3Ftt-0001ab-4v for qemu-devel@nongnu.org; Tue, 22 Oct 2024 10:30:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3Ftq-0007Fp-Vb for qemu-devel@nongnu.org; Tue, 22 Oct 2024 10:30:20 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-177-w2NRoPHROc-4vH9Is8SCCQ-1; Tue, 22 Oct 2024 10:30:14 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6732819560AD; Tue, 22 Oct 2024 14:30:13 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.116.80]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D05391955F42; Tue, 22 Oct 2024 14:30:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729607417; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S70GhYB7laEL2fnTCNmkV4yqr3u8YRvyEUuIY22drcU=; b=Xnk6PrwSwdGNp2mw4Ci37rnG5UNSJuPTapSWyrOa6zsm9BAvFoAJ+adRYxJ2ANZZQbFjqD lbcOI+yH5+XHKlAYDJ4UA8eUPElC/Bn0QnBvu+sS81RZyG7ZoPXOeeUdCdCmsqifsPkO3W 8deVkLGUrA6VO3xj7YscUjgShlACEkw= X-MC-Unique: w2NRoPHROc-4vH9Is8SCCQ-1 From: Dehan Meng To: qemu-devel@nongnu.org Cc: demeng@redhat.com, kkostiuk@redhat.com, michael.roth@amd.com, peter.maydell@linaro.org, berrange@redhat.com Subject: [PATCH v4 3/5] qemu-ga: Avoiding freeing line prematurely Date: Tue, 22 Oct 2024 22:29:46 +0800 Message-Id: <20241022142948.531325-4-demeng@redhat.com> In-Reply-To: <20241022142948.531325-1-demeng@redhat.com> References: <20241022142948.531325-1-demeng@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=demeng@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.519, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.697, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1729607466728116600 Content-Type: text/plain; charset="utf-8" It's now only freed at the end of the function. Signed-off-by: Dehan Meng --- qga/commands-linux.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/qga/commands-linux.c b/qga/commands-linux.c index 32bf1b8ce7..c6bda78de6 100644 --- a/qga/commands-linux.c +++ b/qga/commands-linux.c @@ -2137,8 +2137,7 @@ GuestNetworkRouteList *qmp_guest_network_get_route(Er= ror **errp) is_ipv6 =3D (i =3D=3D 1); fp =3D fopen(routeFiles[i], "r"); if (fp =3D=3D NULL) { - error_setg_errno(errp, errno, "open(\"%s\")", routeFiles[i]); - free(line); + error_setg_errno(errp, errno, "open(\"%s\")", route_files[i]); continue; } =20 @@ -2226,9 +2225,8 @@ GuestNetworkRouteList *qmp_guest_network_get_route(Er= ror **errp) QAPI_LIST_APPEND(tail, route); } =20 - free(line); fclose(fp); } - + free(line); return head; } --=20 2.40.1 From nobody Tue Oct 22 22:21:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1729607502; cv=none; d=zohomail.com; s=zohoarc; b=SF+QMMAOTUkJgWc70vNlVHtG9p4q3csk58F5avXuYvLI8k+sUr6I7D6r1EKP6msA6zZKnGlrNq0E/R+nEIHasI/txK0u9iH9w4c7Gwbtx8KdDdGqV4q44IhysM9wwxrppd0y7qypS8oLTGaXVNojLDT54TVHvztzncUlUaBFbGI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729607502; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KDB7yqyLSkekI+4rK0f7/fU5zZnfA/c1IE3lqJrMDJI=; b=bJrrjANnA8eZ6rp5NAvlMfQUOyjpn8KcpHSEdLLUqDDm9oWlObqTmNwu9sTN0M30Aa4MVZmn6VYE+iiyunl+M5FLz9Ys1MinOUVLwlYGYc5JhrqCxPvAnDmMMSuEDiL6LjmUvQOh15QAk3GG2dUNtaOQtWsK/nPXsAb3WYDfVPU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172960750293775.07639921129817; Tue, 22 Oct 2024 07:31:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3FuX-0001z5-JA; Tue, 22 Oct 2024 10:31:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3Fu0-0001cP-7n for qemu-devel@nongnu.org; Tue, 22 Oct 2024 10:30:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3Fty-0007Gk-HQ for qemu-devel@nongnu.org; Tue, 22 Oct 2024 10:30:28 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-240-9b7LBj-QO3-JxLnSUS8Pmw-1; Tue, 22 Oct 2024 10:30:20 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DDD341955EA8; Tue, 22 Oct 2024 14:30:17 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.116.80]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4738619560AE; Tue, 22 Oct 2024 14:30:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729607425; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KDB7yqyLSkekI+4rK0f7/fU5zZnfA/c1IE3lqJrMDJI=; b=iNhH5QayARR7X8359kTaqoZwMAUwnx5xdCJ2tOlPJr79IhYQipo/5/5rZm51jDU33x/Ph3 2pMLUXR2Z3N8PyvWr1HbgY/fBi6t2/8h9SLvivJ7kw5oFmy049Gegr4+hyeqCfjLGUQo7w V1bkyy7w6+F0v+u9L8xA2c/+iE9PE3I= X-MC-Unique: 9b7LBj-QO3-JxLnSUS8Pmw-1 From: Dehan Meng To: qemu-devel@nongnu.org Cc: demeng@redhat.com, kkostiuk@redhat.com, michael.roth@amd.com, peter.maydell@linaro.org, berrange@redhat.com Subject: [PATCH v4 4/5] qemu-ga: For correcting code style Date: Tue, 22 Oct 2024 22:29:47 +0800 Message-Id: <20241022142948.531325-5-demeng@redhat.com> In-Reply-To: <20241022142948.531325-1-demeng@redhat.com> References: <20241022142948.531325-1-demeng@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=demeng@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.519, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1729607505304116600 Content-Type: text/plain; charset="utf-8" Variable declarations moved to the beginning of blocks Followed the coding style of using snake_case for variable names. And merged redundant route and networkroute variables. Signed-off-by: Dehan Meng --- qga/commands-linux.c | 123 ++++++++++++++++++++----------------------- 1 file changed, 58 insertions(+), 65 deletions(-) diff --git a/qga/commands-linux.c b/qga/commands-linux.c index c6bda78de6..9fb31956b4 100644 --- a/qga/commands-linux.c +++ b/qga/commands-linux.c @@ -2094,12 +2094,12 @@ GuestCpuStatsList *qmp_guest_get_cpustats(Error **e= rrp) return head; } =20 -static char *hexToIPAddress(const void *hexValue, int is_ipv6) +static char *hex_to_ip_address(const void *hex_value, int is_ipv6) { if (is_ipv6) { char addr[INET6_ADDRSTRLEN]; struct in6_addr in6; - const char *hexStr =3D (const char *)hexValue; + const char *hex_str =3D (const char *)hex_value; int i; =20 for (i =3D 0; i < 16; i++) { @@ -2111,11 +2111,11 @@ static char *hexToIPAddress(const void *hexValue, i= nt is_ipv6) =20 return g_strdup(addr); } else { - unsigned int hexInt =3D *(unsigned int *)hexValue; - unsigned int byte1 =3D (hexInt >> 24) & 0xFF; - unsigned int byte2 =3D (hexInt >> 16) & 0xFF; - unsigned int byte3 =3D (hexInt >> 8) & 0xFF; - unsigned int byte4 =3D hexInt & 0xFF; + unsigned int hex_int =3D *(unsigned int *)hex_value; + unsigned int byte1 =3D (hex_int >> 24) & 0xFF; + unsigned int byte2 =3D (hex_int >> 16) & 0xFF; + unsigned int byte3 =3D (hex_int >> 8) & 0xFF; + unsigned int byte4 =3D hex_int & 0xFF; =20 return g_strdup_printf("%u.%u.%u.%u", byte4, byte3, byte2, byte1); } @@ -2131,6 +2131,7 @@ GuestNetworkRouteList *qmp_guest_network_get_route(Er= ror **errp) int firstLine; int is_ipv6; int i; + char iface[IFNAMSIZ]; =20 for (i =3D 0; i < 2; i++) { firstLine =3D 1; @@ -2146,80 +2147,72 @@ GuestNetworkRouteList *qmp_guest_network_get_route(= Error **errp) firstLine =3D 0; continue; } - GuestNetworkRoute *route =3D NULL; - GuestNetworkRoute *networkroute; - char Iface[IFNAMSIZ]; - if (is_ipv6) { - char Destination[33], Source[33], NextHop[33]; - int DesPrefixlen, SrcPrefixlen, Metric, RefCnt, Use, Flags; =20 - /* Parse the line and extract the values */ + if (is_ipv6) { + char destination[33], source[33], next_hop[33]; + int des_prefixlen, src_prefixlen, metric, refcnt, use, fla= gs; if (sscanf(line, "%32s %x %32s %x %32s %x %x %x %x %s", - Destination, &DesPrefixlen, Source, - &SrcPrefixlen, NextHop, &Metric, &RefCnt, - &Use, &Flags, Iface) !=3D 10) { + destination, &des_prefixlen, source, + &src_prefixlen, next_hop, &metric, &refcnt, + &use, &flags, iface) !=3D 10) { continue; } =20 - route =3D g_new0(GuestNetworkRoute, 1); - networkroute =3D route; - networkroute->iface =3D g_strdup(Iface); - networkroute->destination =3D hexToIPAddress(Destination, = 1); - if (networkroute->destination =3D=3D NULL) { + GuestNetworkRoute *route =3D g_new0(GuestNetworkRoute, 1); + + route->destination =3D hex_to_ip_address(destination, 1); + if (route->destination =3D=3D NULL) { g_free(route); continue; } - networkroute->metric =3D Metric; - networkroute->source =3D hexToIPAddress(Source, 1); - networkroute->desprefixlen =3D g_strdup_printf( - "%d", DesPrefixlen - ); - networkroute->srcprefixlen =3D g_strdup_printf( - "%d", SrcPrefixlen - ); - networkroute->nexthop =3D hexToIPAddress(NextHop, 1); - networkroute->has_flags =3D true; - networkroute->flags =3D Flags; - networkroute->has_refcnt =3D true; - networkroute->refcnt =3D RefCnt; - networkroute->has_use =3D true; - networkroute->use =3D Use; - networkroute->version =3D 6; + route->iface =3D g_strdup(iface); + route->destination =3D hex_to_ip_address(destination, 1); + route->source =3D hex_to_ip_address(source, 1); + route->nexthop =3D hex_to_ip_address(next_hop, 1); + route->desprefixlen =3D g_strdup_printf("%d", des_prefixle= n); + route->srcprefixlen =3D g_strdup_printf("%d", src_prefixle= n); + route->metric =3D metric; + route->has_flags =3D true; + route->flags =3D flags; + route->has_refcnt =3D true; + route->refcnt =3D refcnt; + route->has_use =3D true; + route->use =3D use; + route->version =3D 6; } else { - unsigned int Destination, Gateway, Mask, Flags; - int RefCnt, Use, Metric, MTU, Window, IRTT; - - /* Parse the line and extract the values */ + unsigned int destination, gateway, mask, flags; + int refcnt, use, metric, mtu, window, irtt; if (sscanf(line, "%s %X %X %x %d %d %d %X %d %d %d", - Iface, &Destination, &Gateway, &Flags, &RefCnt, - &Use, &Metric, &Mask, &MTU, &Window, &IRTT) != =3D 11) { + iface, &destination, &gateway, &flags, &refcnt, + &use, &metric, &mask, &mtu, &window, &irtt) != =3D 11) { continue; } =20 - route =3D g_new0(GuestNetworkRoute, 1); - networkroute =3D route; - networkroute->iface =3D g_strdup(Iface); - networkroute->destination =3D hexToIPAddress(&Destination,= 0); - if (networkroute->destination =3D=3D NULL) { + GuestNetworkRoute *route =3D g_new0(GuestNetworkRoute, 1); + + route->destination =3D hex_to_ip_address(destination, 1); + if (route->destination =3D=3D NULL) { g_free(route); continue; } - networkroute->gateway =3D hexToIPAddress(&Gateway, 0); - networkroute->mask =3D hexToIPAddress(&Mask, 0); - networkroute->metric =3D Metric; - networkroute->has_flags =3D true; - networkroute->flags =3D Flags; - networkroute->has_refcnt =3D true; - networkroute->refcnt =3D RefCnt; - networkroute->has_use =3D true; - networkroute->use =3D Use; - networkroute->has_mtu =3D true; - networkroute->mtu =3D MTU; - networkroute->has_window =3D true; - networkroute->window =3D Window; - networkroute->has_irtt =3D true; - networkroute->irtt =3D IRTT; - networkroute->version =3D 4; + route->iface =3D g_strdup(iface); + route->destination =3D hex_to_ip_address(&destination, 0); + route->gateway =3D hex_to_ip_address(&gateway, 0); + route->mask =3D hex_to_ip_address(&mask, 0); + route->metric =3D metric; + route->has_flags =3D true; + route->flags =3D flags; + route->has_refcnt =3D true; + route->refcnt =3D refcnt; + route->has_use =3D true; + route->use =3D use; + route->has_mtu =3D true; + route->mtu =3D mtu; + route->has_window =3D true; + route->window =3D window; + route->has_irtt =3D true; + route->irtt =3D irtt; + route->version =3D 4; } =20 QAPI_LIST_APPEND(tail, route); --=20 2.40.1 From nobody Tue Oct 22 22:21:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1729607543; cv=none; d=zohomail.com; s=zohoarc; b=jspbu12R2sCEdp+4+J2O6UeKx8N49udfeloJ/knI4/adY3vsdcQFhJ3wvKLWn4qTRofQKZuc4iOZkT8PUUCaR96y0k1dnZu5uG9FuvjLZ3lVHeqBBfKigITukZ5TIuwnvqYQiuJpuq4iU9B3zQ2i5UqYIcIPFRhJmy9bZaTcxa4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729607543; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PHowBr7x7UYYST4buL7npbj0tciDcR1xEyoNXjo5oMw=; b=XUFkN5Jq26iTII1k6MVi502vWnDwY3bK1i+7dl754tirII0Vf8cXr/gYBykW8A94c1B0JeE/EwOpliLgLTd5vADahRUU1CF6US5lWeNEgS5gpgHDBlF3mFxHaRhbC4oqd2sOdEudlB3tMYOUmwFKbJxstHchcng/vKfgR9TNQdo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729607543132357.2321908551729; Tue, 22 Oct 2024 07:32:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3FuZ-00026f-5w; Tue, 22 Oct 2024 10:31:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3Fu0-0001cN-33 for qemu-devel@nongnu.org; Tue, 22 Oct 2024 10:30:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3Fty-0007Gm-HQ for qemu-devel@nongnu.org; Tue, 22 Oct 2024 10:30:27 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-VLStvPG2MGy-eN0QbTWThg-1; Tue, 22 Oct 2024 10:30:23 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A58171954196; Tue, 22 Oct 2024 14:30:22 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.116.80]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C1BEE19560AE; Tue, 22 Oct 2024 14:30:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729607425; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PHowBr7x7UYYST4buL7npbj0tciDcR1xEyoNXjo5oMw=; b=fbf47yzQ8xdBKdrYERhoDkhNP7pYUl/3n+Cijqk/smk4fgLxZjLs+VLESGSv4arJxSBeZi gqlGlrN/NbUoaAVBEbA1L7hfKVL6VEwuJiO9fzlrnlH319k6pNuZeUsFuxpKQ+HzMpWoGE 0bCGKIWyjG1SPpcOWg3VZ7zICiTy6Jk= X-MC-Unique: VLStvPG2MGy-eN0QbTWThg-1 From: Dehan Meng To: qemu-devel@nongnu.org Cc: demeng@redhat.com, kkostiuk@redhat.com, michael.roth@amd.com, peter.maydell@linaro.org, berrange@redhat.com Subject: [PATCH v4 5/5] qemu-ga: Replace g_new0() with g_autoptr() Date: Tue, 22 Oct 2024 22:29:48 +0800 Message-Id: <20241022142948.531325-6-demeng@redhat.com> In-Reply-To: <20241022142948.531325-1-demeng@redhat.com> References: <20241022142948.531325-1-demeng@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=demeng@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.519, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1729607543842116600 Content-Type: text/plain; charset="utf-8" Replace g_new0() with g_autoptr() to simplify the code Signed-off-by: Dehan Meng --- qga/commands-linux.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/qga/commands-linux.c b/qga/commands-linux.c index 9fb31956b4..ee4f345938 100644 --- a/qga/commands-linux.c +++ b/qga/commands-linux.c @@ -2158,15 +2158,13 @@ GuestNetworkRouteList *qmp_guest_network_get_route(= Error **errp) continue; } =20 - GuestNetworkRoute *route =3D g_new0(GuestNetworkRoute, 1); + g_autoptr(GuestNetworkRoute) route =3D g_new0(GuestNetwork= Route, 1); =20 route->destination =3D hex_to_ip_address(destination, 1); - if (route->destination =3D=3D NULL) { - g_free(route); + route->iface =3D g_strdup(iface); + if (route->destination =3D=3D NULL || route->iface =3D=3D= NULL) { continue; } - route->iface =3D g_strdup(iface); - route->destination =3D hex_to_ip_address(destination, 1); route->source =3D hex_to_ip_address(source, 1); route->nexthop =3D hex_to_ip_address(next_hop, 1); route->desprefixlen =3D g_strdup_printf("%d", des_prefixle= n); @@ -2188,15 +2186,13 @@ GuestNetworkRouteList *qmp_guest_network_get_route(= Error **errp) continue; } =20 - GuestNetworkRoute *route =3D g_new0(GuestNetworkRoute, 1); + g_autoptr(GuestNetworkRoute) route =3D g_new0(GuestNetwork= Route, 1); =20 route->destination =3D hex_to_ip_address(destination, 1); - if (route->destination =3D=3D NULL) { - g_free(route); + route->iface =3D g_strdup(iface); + if (route->destination =3D=3D NULL || route->iface =3D=3D= NULL) { continue; } - route->iface =3D g_strdup(iface); - route->destination =3D hex_to_ip_address(&destination, 0); route->gateway =3D hex_to_ip_address(&gateway, 0); route->mask =3D hex_to_ip_address(&mask, 0); route->metric =3D metric; --=20 2.40.1