From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tiwei Bie Subject: [PATCH v2 2/2] examples/vhost: fix path allocation failure handling Date: Tue, 15 Jan 2019 15:13:24 +0800 Message-ID: <20190115071324.26707-3-tiwei.bie@intel.com> References: <20190115071324.26707-1-tiwei.bie@intel.com> Cc: stable@dpdk.org To: maxime.coquelin@redhat.com, zhihong.wang@intel.com, thomas@monjalon.net, dev@dpdk.org Return-path: In-Reply-To: <20190115071324.26707-1-tiwei.bie@intel.com> 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++; -- 2.17.1