From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C3072A046B for ; Tue, 20 Aug 2019 15:16:25 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 965FF1BEC9; Tue, 20 Aug 2019 15:16:25 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 5C9261BEB4 for ; Tue, 20 Aug 2019 15:16:23 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Aug 2019 06:16:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,408,1559545200"; d="scan'208";a="329705953" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga004.jf.intel.com with ESMTP; 20 Aug 2019 06:16:22 -0700 Received: from fmsmsx157.amr.corp.intel.com (10.18.116.73) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 20 Aug 2019 06:16:21 -0700 Received: from fmsmsx105.amr.corp.intel.com ([169.254.4.93]) by FMSMSX157.amr.corp.intel.com ([169.254.14.57]) with mapi id 14.03.0439.000; Tue, 20 Aug 2019 06:16:21 -0700 From: "Harris, James R" To: "Burakov, Anatoly" CC: "dev@dpdk.org" Thread-Topic: [PATCH] vfio: free mp_reply msgs in failure cases Thread-Index: AQHVV1kLwNVrXt+oTU6x15Og9obku6cEBDhK Date: Tue, 20 Aug 2019 13:16:20 +0000 Message-ID: References: <156595762238.18723.10089009448135563310.stgit@jrharri1-skx>, In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] vfio: free mp_reply msgs in failure cases X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" > On Aug 20, 2019, at 6:13 AM, Burakov, Anatoly = wrote: >=20 >> On 16-Aug-19 1:13 PM, Jim Harris wrote: >> The code checks both rte_mp_request_sync() return >> code and that the number of messages in the reply >> equals 1. If rte_mp_request_sync() succeeds but >> there was more than one message, those messages >> would get leaked. >> Found via code review by Anatoly Burakov of patches >> that used the vhost code as a template for using >> rte_mp_request_sync(). >> Signed-off-by: Jim Harris >> --- >> lib/librte_eal/linux/eal/eal_vfio.c | 16 ++++++++-------- >> 1 file changed, 8 insertions(+), 8 deletions(-) >> diff --git a/lib/librte_eal/linux/eal/eal_vfio.c b/lib/librte_eal/linux/= eal/eal_vfio.c >> index 501c74f23..d9541b122 100644 >> --- a/lib/librte_eal/linux/eal/eal_vfio.c >> +++ b/lib/librte_eal/linux/eal/eal_vfio.c >> @@ -264,7 +264,7 @@ vfio_open_group_fd(int iommu_group_num) >> int vfio_group_fd; >> char filename[PATH_MAX]; >> struct rte_mp_msg mp_req, *mp_rep; >> - struct rte_mp_reply mp_reply; >> + struct rte_mp_reply mp_reply =3D {0}; >> struct timespec ts =3D {.tv_sec =3D 5, .tv_nsec =3D 0}; >> struct vfio_mp_param *p =3D (struct vfio_mp_param *)mp_req.param; >> @@ -320,9 +320,9 @@ vfio_open_group_fd(int iommu_group_num) >> RTE_LOG(ERR, EAL, " bad VFIO group fd\n"); >> vfio_group_fd =3D 0; >> } >> - free(mp_reply.msgs); >> } >> + free(mp_reply.msgs); >=20 > That's not quite correct. This fixes the problem of missing free() when n= b_received mismatches, but this /adds/ a problem of doing an unnecessary fr= ee() when rte_mp_request_sync() returns -1. Same for other places, i believ= e. This would just resolve to free(NULL) in the -1 case. Jim >=20 > --=20 > Thanks, > Anatoly