graph: fix null dereference in stats
authorHongbo Zheng <zhenghongbo3@huawei.com>
Thu, 6 May 2021 07:16:27 +0000 (15:16 +0800)
committerDavid Marchand <david.marchand@redhat.com>
Thu, 3 Jun 2021 16:35:57 +0000 (18:35 +0200)
In function 'stats_mem_init', pointer 'stats' should
be confirmed not null before memset it.

Fixes: af1ae8b6a32c ("graph: implement stats")
Cc: stable@dpdk.org
Signed-off-by: Hongbo Zheng <zhenghongbo3@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
Reviewed-by: Jerin Jacob <jerinj@marvell.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
lib/graph/graph_stats.c

index 30e295d..aa70929 100644 (file)
@@ -119,8 +119,8 @@ stats_mem_init(struct cluster *cluster,
        cluster_node_size = RTE_ALIGN(cluster_node_size, RTE_CACHE_LINE_SIZE);
 
        stats = realloc(NULL, sz);
-       memset(stats, 0, sz);
        if (stats) {
+               memset(stats, 0, sz);
                stats->fn = fn;
                stats->cluster_node_size = cluster_node_size;
                stats->max_nodes = 0;