If users configure the 'vhost-sock-dir' for dpdk, the memory
allocated by xstrdup(ovs_rundir()) is not freed. This patch
allows the process_vhost_flags to xstrdup() for val or
default_val according to configuration and the caller must
free new_val when it is no longer needed.

Fixes: 01961bbdd34a ("dpdk: New module with some code from netdev-dpdk.")
CC: Daniele Di Proietto <[email protected]>
Signed-off-by: nickcooper-zhangtonghao <[email protected]>
---
 lib/dpdk.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/dpdk.c b/lib/dpdk.c
index 9ae2491..c1626e2 100644
--- a/lib/dpdk.c
+++ b/lib/dpdk.c
@@ -39,7 +39,7 @@ VLOG_DEFINE_THIS_MODULE(dpdk);
 static char *vhost_sock_dir = NULL;   /* Location of vhost-user sockets */
 
 static int
-process_vhost_flags(char *flag, char *default_val, int size,
+process_vhost_flags(char *flag, const char *default_val, int size,
                     const struct smap *ovs_other_config,
                     char **new_val)
 {
@@ -57,7 +57,7 @@ process_vhost_flags(char *flag, char *default_val, int size,
         VLOG_INFO("User-provided %s in use: %s", flag, *new_val);
     } else {
         VLOG_INFO("No %s provided - defaulting to %s", flag, default_val);
-        *new_val = default_val;
+        *new_val = xstrdup(default_val);
     }
 
     return changed;
@@ -273,7 +273,7 @@ dpdk_init__(const struct smap *ovs_other_config)
     cpu_set_t cpuset;
     char *sock_dir_subcomponent;
 
-    if (process_vhost_flags("vhost-sock-dir", xstrdup(ovs_rundir()),
+    if (process_vhost_flags("vhost-sock-dir", ovs_rundir(),
                             NAME_MAX, ovs_other_config,
                             &sock_dir_subcomponent)) {
         struct stat s;
-- 
1.8.3.1



_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to