From nobody Wed Nov 27 04:32:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700450145764335.4519001062728; Sun, 19 Nov 2023 19:15:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r4ukg-0003M2-NB; Sun, 19 Nov 2023 22:15:10 -0500 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 1r4ukc-0003Lr-Q7 for qemu-devel@nongnu.org; Sun, 19 Nov 2023 22:15:06 -0500 Received: from mailgw.kylinos.cn ([124.126.103.232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r4ukY-000131-GK for qemu-devel@nongnu.org; Sun, 19 Nov 2023 22:15:06 -0500 Received: from thinkpadx13gen2i.. [(116.128.244.169)] by mailgw (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 196459290; Mon, 20 Nov 2023 11:14:34 +0800 X-UUID: f07d96c7d1504f0a8612e4b653e94105-20231120 X-CID-O-RULE: Release_Ham X-CID-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.32, REQID:bb247b21-153d-4cf6-8eba-e1ac0bdd0575, IP:5, U RL:0,TC:0,Content:0,EDM:25,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:15 X-CID-INFO: VERSION:1.1.32, REQID:bb247b21-153d-4cf6-8eba-e1ac0bdd0575, IP:5, URL :0,TC:0,Content:0,EDM:25,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:15 X-CID-META: VersionHash:5f78ec9, CLOUDID:6f45d672-1bd3-4f48-b671-ada88705968c, B ulkID:231120111436TUHAXQCD,BulkQuantity:0,Recheck:0,SF:66|24|17|19|44|102, TC:nil,Content:0,EDM:5,IP:-2,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0, OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI,TF_CID_SPAM_SNR X-UUID: f07d96c7d1504f0a8612e4b653e94105-20231120 X-User: zhouzongmin@kylinos.cn From: Zongmin Zhou To: peterx@redhat.com Cc: berrange@redhat.com, farosas@suse.de, leobras@redhat.com, qemu-devel@nongnu.org, quintela@redhat.com, Zongmin Zhou Subject: [PATCH v3] migration: free 'saddr' since be no longer used Date: Mon, 20 Nov 2023 11:14:28 +0800 Message-Id: <20231120031428.908295-1-zhouzongmin@kylinos.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=124.126.103.232; envelope-from=zhouzongmin@kylinos.cn; helo=mailgw.kylinos.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, UNPARSEABLE_RELAY=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-ZM-MESSAGEID: 1700450147003100001 Content-Type: text/plain; charset="utf-8" Since socket_parse() will allocate memory for 'saddr',and its value will pass to 'addr' that allocated by migrate_uri_parse(), then 'saddr' will no longer used,need to free. But due to 'saddr->u' is shallow copying the contents of the union, the members of this union containing allocated strings,and will be used aft= er that. So just free 'saddr' itself without doing a deep free on the contents of th= e SocketAddress. Fixes: 72a8192e225c ("migration: convert migration 'uri' into 'MigrateAddre= ss'") Signed-off-by: Zongmin Zhou Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Xu --- migration/migration.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 28a34c9068..1832dad618 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -462,7 +462,6 @@ bool migrate_uri_parse(const char *uri, MigrationChanne= l **channel, { g_autoptr(MigrationChannel) val =3D g_new0(MigrationChannel, 1); g_autoptr(MigrationAddress) addr =3D g_new0(MigrationAddress, 1); - SocketAddress *saddr =3D NULL; InetSocketAddress *isock =3D &addr->u.rdma; strList **tail =3D &addr->u.exec.args; =20 @@ -487,12 +486,14 @@ bool migrate_uri_parse(const char *uri, MigrationChan= nel **channel, strstart(uri, "vsock:", NULL) || strstart(uri, "fd:", NULL)) { addr->transport =3D MIGRATION_ADDRESS_TYPE_SOCKET; - saddr =3D socket_parse(uri, errp); + SocketAddress *saddr =3D socket_parse(uri, errp); if (!saddr) { return false; } addr->u.socket.type =3D saddr->type; addr->u.socket.u =3D saddr->u; + /* Don't free the objects inside; their ownership moved to "addr" = */ + g_free(saddr); } else if (strstart(uri, "file:", NULL)) { addr->transport =3D MIGRATION_ADDRESS_TYPE_FILE; addr->u.file.filename =3D g_strdup(uri + strlen("file:")); --=20 2.34.1