From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id AE5EF1B43C; Mon, 14 Jan 2019 04:37:52 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Jan 2019 19:37:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,476,1539673200"; d="scan'208";a="109633051" Received: from dpdk-tbie.sh.intel.com ([10.67.104.173]) by orsmga008.jf.intel.com with ESMTP; 13 Jan 2019 19:37:51 -0800 From: Tiwei Bie To: maxime.coquelin@redhat.com, zhihong.wang@intel.com, dev@dpdk.org Cc: stable@dpdk.org Date: Mon, 14 Jan 2019 11:34:43 +0800 Message-Id: <20190114033444.13026-2-tiwei.bie@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190114033444.13026-1-tiwei.bie@intel.com> References: <20190114033444.13026-1-tiwei.bie@intel.com> Subject: [dpdk-stable] [PATCH 1/2] vhost: fix memory leak on realloc failure X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Jan 2019 03:37:53 -0000 When realloc() fails, the original block isn't freed. Fixes: e246896178e6 ("vhost: get guest/host physical address mappings") Cc: stable@dpdk.org Signed-off-by: Tiwei Bie --- lib/librte_vhost/vhost_user.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 8fec773d5..5222f77dd 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -730,13 +730,16 @@ add_one_guest_page(struct virtio_net *dev, uint64_t guest_phys_addr, uint64_t host_phys_addr, uint64_t size) { struct guest_page *page, *last_page; + struct guest_page *old_pages; if (dev->nr_guest_pages == dev->max_guest_pages) { dev->max_guest_pages *= 2; + old_pages = dev->guest_pages; dev->guest_pages = realloc(dev->guest_pages, dev->max_guest_pages * sizeof(*page)); if (!dev->guest_pages) { RTE_LOG(ERR, VHOST_CONFIG, "cannot realloc guest_pages\n"); + free(old_pages); return -1; } } -- 2.17.1