[2/2] examples/vhost: fix realloc failure

Message ID 20190114033444.13026-3-tiwei.bie@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series Fixes for realloc() in vhost |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Tiwei Bie Jan. 14, 2019, 3:34 a.m. UTC
  Fixes: ad0eef4d2203 ("examples/vhost: support multiple socket files")
Cc: stable@dpdk.org

Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
---
 examples/vhost/main.c | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Comments

Maxime Coquelin Jan. 14, 2019, 10:20 a.m. UTC | #1
On 1/14/19 4:34 AM, Tiwei Bie wrote:
> Fixes: ad0eef4d2203 ("examples/vhost: support multiple socket files")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
> ---
>   examples/vhost/main.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  
Thomas Monjalon Jan. 15, 2019, 1:56 a.m. UTC | #2
14/01/2019 04:34, Tiwei Bie:
> Fixes: ad0eef4d2203 ("examples/vhost: support multiple socket files")
> Cc: stable@dpdk.org

Please add some explanations about what was wrong.

About the title, do you mean "fix path allocation failure handling" ?
  
Tiwei Bie Jan. 15, 2019, 6:53 a.m. UTC | #3
On Tue, Jan 15, 2019 at 02:56:39AM +0100, Thomas Monjalon wrote:
> 14/01/2019 04:34, Tiwei Bie:
> > Fixes: ad0eef4d2203 ("examples/vhost: support multiple socket files")
> > Cc: stable@dpdk.org
> 
> Please add some explanations about what was wrong.

My bad. Will do it in the next version.

> 
> About the title, do you mean "fix path allocation failure handling" ?

Yeah, thanks for the suggestion!

Thanks
  

Patch

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index dc9ea1018..23fee445a 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -375,11 +375,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++;