Hi,
The memset call is made right after malloc call. To fix this, add the null
check right after malloc and then do memset.
Please find the patch below.
Thanks and regards,
Gaurav.
From 8083a35f85c6047f0377883ed66ae147f85fd3a9 Mon Sep 17 00:00:00 2001
From: Gaurav Singh <gaurav1086@xxxxxxxxx>
Date: Sat, 6 Jun 2020 19:42:53 -0400
Subject: [PATCH] bpf_stats_record: Add null check after malloc
Signed-off-by: Gaurav Singh <gaurav1086@xxxxxxxxx>
---
samples/bpf/xdp_rxq_info_user.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/bpf/xdp_rxq_info_user.c
b/samples/bpf/xdp_rxq_info_user.c
index 4fe47502ebed..c44b9a844066 100644
--- a/samples/bpf/xdp_rxq_info_user.c
+++ b/samples/bpf/xdp_rxq_info_user.c
@@ -233,11 +233,11 @@ static struct stats_record *alloc_stats_record(void)
int i;
rec = malloc(sizeof(*rec));
- memset(rec, 0, sizeof(*rec));
if (!rec) {
fprintf(stderr, "Mem alloc error\n");
exit(EXIT_FAIL_MEM);
}
+ memset(rec, 0, sizeof(*rec));
rec->rxq = alloc_record_per_rxq();
for (i = 0; i < nr_rxqs; i++)
rec->rxq[i].cpu = alloc_record_per_cpu();