From nobody Sun Feb 8 20:34:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1562229778; cv=none; d=zoho.com; s=zohoarc; b=HuCr39WWVPUiyGFtZBHetjO/gAZtZxFPz2qTMc+f0j84/OlmzYL3++8CPnHY3GPev4SXMBQUCXMgtEaryETUUkpTAReinClQZ4nv5ALos5M+uKieaB/OmOAHiLu9mRxvbQiZouzHbDkSdsXz1Khw6aAhbvejtSVTsapujMymdmA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562229778; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=EvWtB17RYO/J9ImgZxEjzjfGxYZfBIvIPzx+jgnWODw=; b=H7N8alKHpoC/qFhIyeV9DnSRfCL7kJxv2YlXR7u+DF2jkk1i+oN/j1Q4vK6COB5vRhdfohBzSR/KRA7QNq76nGuVl9it61K/2VI/35vm9SwfmZ3LgueNUoOwL7tekywlKsuLWXEQ+00Yhvxr25g7/qsKNdRQ8TYV7GjmX43k+/I= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562229778198190.74678777131635; Thu, 4 Jul 2019 01:42:58 -0700 (PDT) Received: from localhost ([::1]:43562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hixKL-0002Px-9d for importer@patchew.org; Thu, 04 Jul 2019 04:42:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55818) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hixJH-0001X9-Ps for qemu-devel@nongnu.org; Thu, 04 Jul 2019 04:41:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hixJG-0000C9-RP for qemu-devel@nongnu.org; Thu, 04 Jul 2019 04:41:43 -0400 Received: from mga07.intel.com ([134.134.136.100]:63075) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hixJG-0000BM-Jh for qemu-devel@nongnu.org; Thu, 04 Jul 2019 04:41:42 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jul 2019 01:41:41 -0700 Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by orsmga002.jf.intel.com with ESMTP; 04 Jul 2019 01:41:39 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,450,1557212400"; d="scan'208";a="175192441" From: Zhang Chen To: Li Zhijian , Peter Maydell , Jason Wang , qemu-dev Date: Thu, 4 Jul 2019 16:36:47 +0800 Message-Id: <20190704083647.30614-1-chen.zhang@intel.com> X-Mailer: git-send-email 2.17.GIT X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.100 Subject: [Qemu-devel] [PATCH V2] net/colo-compare.c: Fix memory leak and code style issue. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Zhang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Zhang Chen This patch to fix the origin "char *data" menory leak, code style issue and add necessary check here. Reported-by: Coverity (CID 1402785) Signed-off-by: Zhang Chen --- net/colo-compare.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 909dd6c6eb..ed349f5f6a 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -127,6 +127,17 @@ static int compare_chr_send(CompareState *s, uint32_t vnet_hdr_len, bool notify_remote_frame); =20 +static bool packet_matches_str(const char *str, + uint8_t *buf, + uint32_t packet_len) +{ + if (packet_len <=3D strlen(str)) { + return false; + } + + return !memcmp(str, buf, strlen(str) + 1); +} + static void notify_remote_frame(CompareState *s) { char msg[] =3D "DO_CHECKPOINT"; @@ -1008,21 +1019,24 @@ static void compare_notify_rs_finalize(SocketReadSt= ate *notify_rs) { CompareState *s =3D container_of(notify_rs, CompareState, notify_rs); =20 - /* Get Xen colo-frame's notify and handle the message */ - char *data =3D g_memdup(notify_rs->buf, notify_rs->packet_len); - char msg[] =3D "COLO_COMPARE_GET_XEN_INIT"; + const char msg[] =3D "COLO_COMPARE_GET_XEN_INIT"; int ret; =20 - if (!strcmp(data, "COLO_USERSPACE_PROXY_INIT")) { + if (packet_matches_str("COLO_USERSPACE_PROXY_INIT", + notify_rs->buf, + notify_rs->packet_len)) { ret =3D compare_chr_send(s, (uint8_t *)msg, strlen(msg), 0, true); if (ret < 0) { error_report("Notify Xen COLO-frame INIT failed"); } - } - - if (!strcmp(data, "COLO_CHECKPOINT")) { + } else if (packet_matches_str("COLO_CHECKPOINT", + notify_rs->buf, + notify_rs->packet_len)) { /* colo-compare do checkpoint, flush pri packet and remove sec pac= ket */ g_queue_foreach(&s->conn_list, colo_flush_packets, s); + } else { + error_report("COLO compare got unsupported instruction '%s'", + (char *)notify_rs->buf); } } =20 --=20 2.17.GIT