diff mbox series

[v5,2/5] devargs: fix memory leak on parsing error

Message ID 1618283653-16510-3-git-send-email-xuemingl@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers show
Series eal: enable global device syntax by default | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Xueming(Steven) Li April 13, 2021, 3:14 a.m. UTC
This patch fixes memory leak in parsing error handling.

Fixes: 338327d731e6 ("devargs: add function to parse device layers")
Cc: gaetan.rivet@6wind.com
Cc: stable@dpdk.org

Signed-off-by: Xueming Li <xuemingl@nvidia.com>
Reviewed-by: Gaetan Rivet <grive@u256.net>
---
 lib/librte_eal/common/eal_common_devargs.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index 48f85ee9c0..e40b91ea66 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -60,6 +60,7 @@  rte_devargs_layers_parse(struct rte_devargs *devargs,
 	size_t nblayer;
 	size_t i = 0;
 	int ret = 0;
+	bool allocated_data = false;
 
 	/* Split each sub-lists. */
 	nblayer = devargs_layer_count(devstr);
@@ -81,6 +82,7 @@  rte_devargs_layers_parse(struct rte_devargs *devargs,
 			ret = -ENOMEM;
 			goto get_out;
 		}
+		allocated_data = true;
 		s = devargs->data;
 	}
 
@@ -163,8 +165,14 @@  rte_devargs_layers_parse(struct rte_devargs *devargs,
 		if (layers[i].kvlist)
 			rte_kvargs_free(layers[i].kvlist);
 	}
-	if (ret != 0)
+	if (ret != 0) {
+		if (allocated_data) {
+			/* Free duplicated data. */
+			free(devargs->data);
+			devargs->data = NULL;
+		}
 		rte_errno = -ret;
+	}
 	return ret;
 }