2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-30 22:05:19 +00:00

dpdk: Fixes memory leak in dpdk_init__().

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: 01961bbdd3 ("dpdk: New module with some code from netdev-dpdk.")
CC: Daniele Di Proietto <diproiettod@vmware.com>
Signed-off-by: nickcooper-zhangtonghao <nic@opencloud.tech>
Reviewed-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com>
This commit is contained in:
nickcooper-zhangtonghao
2017-02-09 03:25:41 -08:00
committed by Daniele Di Proietto
parent d46b603797
commit 6c4f08e23f

View File

@@ -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;