[v2] app/testpmd: fix buffer leak in tm cmdline

Message ID 1530769547-8586-1-git-send-email-nithin.dabilpuram@caviumnetworks.com (mailing list archive)
State Accepted, archived
Delegated to: Cristian Dumitrescu
Headers
Series [v2] app/testpmd: fix buffer leak in tm cmdline |

Checks

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

Commit Message

Nithin Dabilpuram July 5, 2018, 5:45 a.m. UTC
  Free the buffer allocated for shared_shaper_id array in
case of configuration without shared shapers.

Signed-off-by: Nithin Dabilpuram <nithin.dabilpuram@caviumnetworks.com>
Acked-by: Jasvinder Singh <jasvinder.singh@intel.com>
---
v2 changes:
- Modify subject to use proper keyword for test-pmd
- Change author email address

 app/test-pmd/cmdline_tm.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
  

Comments

Thomas Monjalon July 26, 2018, 5:26 p.m. UTC | #1
05/07/2018 07:45, Nithin Dabilpuram:
> Free the buffer allocated for shared_shaper_id array in
> case of configuration without shared shapers.
> 
> Signed-off-by: Nithin Dabilpuram <nithin.dabilpuram@caviumnetworks.com>
> Acked-by: Jasvinder Singh <jasvinder.singh@intel.com>

Applied, thanks
  

Patch

diff --git a/app/test-pmd/cmdline_tm.c b/app/test-pmd/cmdline_tm.c
index c904e44..7c1601f 100644
--- a/app/test-pmd/cmdline_tm.c
+++ b/app/test-pmd/cmdline_tm.c
@@ -1599,10 +1599,12 @@  static void cmd_add_port_tm_nonleaf_node_parsed(void *parsed_result,
 		np.shaper_profile_id = res->shaper_profile_id;
 
 	np.n_shared_shapers = n_shared_shapers;
-	if (np.n_shared_shapers)
+	if (np.n_shared_shapers) {
 		np.shared_shaper_id = &shared_shaper_id[0];
-	else
-		np.shared_shaper_id = NULL;
+	} else {
+		free(shared_shaper_id);
+		shared_shaper_id = NULL;
+	}
 
 	np.nonleaf.n_sp_priorities = res->n_sp_priorities;
 	np.stats_mask = res->stats_mask;
@@ -1758,10 +1760,12 @@  static void cmd_add_port_tm_leaf_node_parsed(void *parsed_result,
 
 	np.n_shared_shapers = n_shared_shapers;
 
-	if (np.n_shared_shapers)
+	if (np.n_shared_shapers) {
 		np.shared_shaper_id = &shared_shaper_id[0];
-	else
-		np.shared_shaper_id = NULL;
+	} else {
+		free(shared_shaper_id);
+		shared_shaper_id = NULL;
+	}
 
 	np.leaf.cman = res->cman_mode;
 	np.leaf.wred.wred_profile_id = res->wred_profile_id;