[dpdk-dev] eal: reset driver name pointer on failure

Message ID 20170124202656.792-1-emmanuel.roullit@gmail.com (mailing list archive)
State Accepted, archived
Headers

Checks

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

Commit Message

Emmanuel Roullit Jan. 24, 2017, 8:26 p.m. UTC
  The pointer set by strdup() needs to be cleared on failure to avoid a
potential double-free from the caller.

Found with clang static analysis:
lib/librte_eal/common/eal_common_devargs.c:123:2:
warning: Attempt to free released memory
        free(buf);
        ^~~~~~~~~

Fixes: 3fe2e5fec82b ("eal: fix argument parsing check")

Signed-off-by: Emmanuel Roullit <emmanuel.roullit@gmail.com>
---
 lib/librte_eal/common/eal_common_devargs.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Thomas Monjalon Jan. 29, 2017, 10:35 p.m. UTC | #1
2017-01-24 21:26, Emmanuel Roullit:
> The pointer set by strdup() needs to be cleared on failure to avoid a
> potential double-free from the caller.
> 
> Found with clang static analysis:
> lib/librte_eal/common/eal_common_devargs.c:123:2:
> warning: Attempt to free released memory
>         free(buf);
>         ^~~~~~~~~
> 
> Fixes: 3fe2e5fec82b ("eal: fix argument parsing check")

The real bug origin is:
Fixes: 0fe11ec592b2 ("eal: add vdev init and uninit")

> Signed-off-by: Emmanuel Roullit <emmanuel.roullit@gmail.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index e403717be..ffa8ad96f 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -72,6 +72,7 @@  rte_eal_parse_devargs_str(const char *devargs_str,
 
 	if (*drvargs == NULL) {
 		free(*drvname);
+		*drvname = NULL;
 		return -1;
 	}
 	return 0;