test/graph: fix memory leak

Message ID 20200514033140.11340-1-kirankumark@marvell.com (mailing list archive)
State Superseded, archived
Headers
Series test/graph: fix memory leak |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-nxp-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/Intel-compilation success Compilation OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-testing fail Testing issues

Commit Message

Kiran Kumar Kokkilagadda May 14, 2020, 3:31 a.m. UTC
  From: Kiran Kumar K <kirankumark@marvell.com>

Fix memory leaks reported by coverity.

Signed-off-by: Kiran Kumar K <kirankumark@marvell.com>
---
 app/test/test_graph.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
  

Comments

Jerin Jacob May 14, 2020, 7:59 a.m. UTC | #1
On Thu, May 14, 2020 at 9:02 AM <kirankumark@marvell.com> wrote:
>
> From: Kiran Kumar K <kirankumark@marvell.com>
>
> Fix memory leaks reported by coverity.

Please add Coverity issue:  and Fixes: tag


>
> Signed-off-by: Kiran Kumar K <kirankumark@marvell.com>
> ---
>  app/test/test_graph.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/app/test/test_graph.c b/app/test/test_graph.c
> index cf6df0744..ed69eda99 100644
> --- a/app/test/test_graph.c
> +++ b/app/test/test_graph.c
> @@ -12,6 +12,7 @@
>  #include <rte_graph.h>
>  #include <rte_graph_worker.h>
>  #include <rte_mbuf.h>
> +#include <rte_random.h>
>
>  #include "test.h"
>
> @@ -145,7 +146,7 @@ uint16_t
>  test_node_worker_source(struct rte_graph *graph, struct rte_node *node,
>                         void **objs, uint16_t nb_objs)
>  {
> -       uint32_t obj_node0 = rand() % 100, obj_node1;
> +       uint32_t obj_node0 = rte_rand() % 100, obj_node1;
>         test_main_t *tm = &test_main;
>         struct rte_mbuf *data;
>         void **next_stream;
> @@ -193,7 +194,7 @@ test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
>         test_main_t *tm = &test_main;
>
>         if (*(uint32_t *)node->ctx == test_node0.id) {
> -               uint32_t obj_node0 = rand() % 100, obj_node1;
> +               uint32_t obj_node0 = rte_rand() % 100, obj_node1;
>                 struct rte_mbuf *data;
>                 uint8_t second_pass = 0;
>                 uint32_t count = 0;
> @@ -496,6 +497,7 @@ test_lookup_functions(void)
>                         printf("Test number of edges for node = %s failed Expected = %d, got %d\n",
>                                tm->test_node[i].node.name,
>                                tm->test_node[i].node.nb_edges, count);
> +                       free(next_edges);
>                         return -1;
>                 }
>
> @@ -505,6 +507,7 @@ test_lookup_functions(void)
>                                 printf("Edge name miss match, expected = %s got = %s\n",
>                                        tm->test_node[i].node.next_nodes[j],
>                                        next_edges[j]);
> +                               free(next_edges);
>                                 return -1;
>                         }
>                 }
> --
> 2.17.1
>
  

Patch

diff --git a/app/test/test_graph.c b/app/test/test_graph.c
index cf6df0744..ed69eda99 100644
--- a/app/test/test_graph.c
+++ b/app/test/test_graph.c
@@ -12,6 +12,7 @@ 
 #include <rte_graph.h>
 #include <rte_graph_worker.h>
 #include <rte_mbuf.h>
+#include <rte_random.h>
 
 #include "test.h"
 
@@ -145,7 +146,7 @@  uint16_t
 test_node_worker_source(struct rte_graph *graph, struct rte_node *node,
 			void **objs, uint16_t nb_objs)
 {
-	uint32_t obj_node0 = rand() % 100, obj_node1;
+	uint32_t obj_node0 = rte_rand() % 100, obj_node1;
 	test_main_t *tm = &test_main;
 	struct rte_mbuf *data;
 	void **next_stream;
@@ -193,7 +194,7 @@  test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 	test_main_t *tm = &test_main;
 
 	if (*(uint32_t *)node->ctx == test_node0.id) {
-		uint32_t obj_node0 = rand() % 100, obj_node1;
+		uint32_t obj_node0 = rte_rand() % 100, obj_node1;
 		struct rte_mbuf *data;
 		uint8_t second_pass = 0;
 		uint32_t count = 0;
@@ -496,6 +497,7 @@  test_lookup_functions(void)
 			printf("Test number of edges for node = %s failed Expected = %d, got %d\n",
 			       tm->test_node[i].node.name,
 			       tm->test_node[i].node.nb_edges, count);
+			free(next_edges);
 			return -1;
 		}
 
@@ -505,6 +507,7 @@  test_lookup_functions(void)
 				printf("Edge name miss match, expected = %s got = %s\n",
 				       tm->test_node[i].node.next_nodes[j],
 				       next_edges[j]);
+				free(next_edges);
 				return -1;
 			}
 		}