From patchwork Tue Jan 15 07:13:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiwei Bie X-Patchwork-Id: 49811 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 291D21B120; Tue, 15 Jan 2019 08:16:05 +0100 (CET) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 9E5661B10C; Tue, 15 Jan 2019 08:16:03 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Jan 2019 23:16:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,480,1539673200"; d="scan'208";a="291626943" Received: from dpdk-tbie.sh.intel.com ([10.67.104.173]) by orsmga005.jf.intel.com with ESMTP; 14 Jan 2019 23:15:59 -0800 From: Tiwei Bie To: maxime.coquelin@redhat.com, zhihong.wang@intel.com, thomas@monjalon.net, dev@dpdk.org Cc: stable@dpdk.org Date: Tue, 15 Jan 2019 15:13:23 +0800 Message-Id: <20190115071324.26707-2-tiwei.bie@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190115071324.26707-1-tiwei.bie@intel.com> References: <20190115071324.26707-1-tiwei.bie@intel.com> Subject: [dpdk-dev] [PATCH v2 1/2] vhost: fix memory leak on realloc failure 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" 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 Reviewed-by: Maxime Coquelin --- 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 1843e032f..4a968ef70 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -733,13 +733,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; } } From patchwork Tue Jan 15 07:13:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiwei Bie X-Patchwork-Id: 49812 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4654A1B131; Tue, 15 Jan 2019 08:16:07 +0100 (CET) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 1FCCB1B120; Tue, 15 Jan 2019 08:16:03 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Jan 2019 23:16:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,480,1539673200"; d="scan'208";a="291626968" Received: from dpdk-tbie.sh.intel.com ([10.67.104.173]) by orsmga005.jf.intel.com with ESMTP; 14 Jan 2019 23:16:01 -0800 From: Tiwei Bie To: maxime.coquelin@redhat.com, zhihong.wang@intel.com, thomas@monjalon.net, dev@dpdk.org Cc: stable@dpdk.org Date: Tue, 15 Jan 2019 15:13:24 +0800 Message-Id: <20190115071324.26707-3-tiwei.bie@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190115071324.26707-1-tiwei.bie@intel.com> References: <20190115071324.26707-1-tiwei.bie@intel.com> Subject: [dpdk-dev] [PATCH v2 2/2] examples/vhost: fix path allocation failure handling 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" Add the missing failure handling for path allocation, as realloc() may fail. Fixes: ad0eef4d2203 ("examples/vhost: support multiple socket files") Cc: stable@dpdk.org Signed-off-by: Tiwei Bie Reviewed-by: Maxime Coquelin --- v2: - Improve the title and add some explanations (Thomas); examples/vhost/main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index 645cf51e9..5e914f58e 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -353,11 +353,19 @@ port_init(uint16_t port) static int us_vhost_parse_socket_path(const char *q_arg) { + char *old; + /* parse number string */ if (strnlen(q_arg, PATH_MAX) == PATH_MAX) return -1; + old = socket_files; socket_files = realloc(socket_files, PATH_MAX * (nb_sockets + 1)); + if (socket_files == NULL) { + free(old); + return -1; + } + snprintf(socket_files + nb_sockets * PATH_MAX, PATH_MAX, "%s", q_arg); nb_sockets++;