Skip to content

Commit

Permalink
net/softnic: fix memory leak in arguments parsing
Browse files Browse the repository at this point in the history
[ upstream commit d8f852f ]

In function pmd_parse_args(), firmware path is duplicated from device
arguments as character string, but is never freed, which cause memory
leak.

This patch changes the type of firmware member of struct pmd_params to
character array, to make memory resource release unnecessary, and
changes the type of name member to character array, to keep the
consistency of character string handling in struct pmd_params.

Fixes: 7e68bc2 ("net/softnic: restructure")

Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
Acked-by: Jasvinder Singh <jasvinder.singh@intel.com>
  • Loading branch information
yudapengx authored and cpaelzer committed Aug 10, 2021
1 parent 8945c5a commit d313979
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
30 changes: 26 additions & 4 deletions drivers/net/softnic/rte_eth_softnic.c
Expand Up @@ -440,14 +440,22 @@ pmd_parse_args(struct pmd_params *p, const char *params)
{
struct rte_kvargs *kvlist;
int ret = 0;
char *firmware = NULL;

kvlist = rte_kvargs_parse(params, pmd_valid_args);
if (kvlist == NULL)
return -EINVAL;

/* Set default values */
memset(p, 0, sizeof(*p));
p->firmware = SOFTNIC_FIRMWARE;
if (rte_strscpy(p->firmware, SOFTNIC_FIRMWARE,
sizeof(p->firmware)) < 0) {
PMD_LOG(WARNING,
"\"%s\": firmware path should be shorter than %zu",
SOFTNIC_FIRMWARE, sizeof(p->firmware));
ret = -EINVAL;
goto out_free;
}
p->cpu_id = SOFTNIC_CPU_ID;
p->sc = SOFTNIC_SC;
p->tm.n_queues = SOFTNIC_TM_N_QUEUES;
Expand All @@ -468,11 +476,20 @@ pmd_parse_args(struct pmd_params *p, const char *params)
/* Firmware script (optional) */
if (rte_kvargs_count(kvlist, PMD_PARAM_FIRMWARE) == 1) {
ret = rte_kvargs_process(kvlist, PMD_PARAM_FIRMWARE,
&get_string, &p->firmware);
&get_string, &firmware);
if (ret < 0)
goto out_free;
}

if (rte_strscpy(p->firmware, firmware,
sizeof(p->firmware)) < 0) {
PMD_LOG(WARNING,
"\"%s\": firmware path should be shorter than %zu",
firmware, sizeof(p->firmware));
free(firmware);
ret = -EINVAL;
goto out_free;
}
free(firmware);
/* Connection listening port (optional) */
if (rte_kvargs_count(kvlist, PMD_PARAM_CONN_PORT) == 1) {
ret = rte_kvargs_process(kvlist, PMD_PARAM_CONN_PORT,
Expand Down Expand Up @@ -621,7 +638,12 @@ pmd_probe(struct rte_vdev_device *vdev)
if (status)
return status;

p.name = name;
if (rte_strscpy(p.name, name, sizeof(p.name)) < 0) {
PMD_LOG(WARNING,
"\"%s\": device name should be shorter than %zu",
name, sizeof(p.name));
return -EINVAL;
}

/* Allocate and initialize soft ethdev private data */
dev_private = pmd_init(&p);
Expand Down
5 changes: 3 additions & 2 deletions drivers/net/softnic/rte_eth_softnic_internals.h
Expand Up @@ -28,14 +28,15 @@
#include "conn.h"

#define NAME_SIZE 64
#define SOFTNIC_PATH_MAX 4096

/**
* PMD Parameters
*/

struct pmd_params {
const char *name;
const char *firmware;
char name[NAME_SIZE];
char firmware[SOFTNIC_PATH_MAX];
uint16_t conn_port;
uint32_t cpu_id;
int sc; /**< Service cores. */
Expand Down

0 comments on commit d313979

Please sign in to comment.