From 6f340f8564acb9e59683670a0987b1e38f63ed37 Mon Sep 17 00:00:00 2001 From: "Yan, Like" Date: Mon, 14 May 2018 14:26:29 +0800 Subject: [PATCH] tools: acrnlog: fix issues founded in static analysis fixed two issues: 1) potential uninitiliazed usage of 'len' in hvlog_read_dev(); 2) NULL dereference of 'last' if 'calloc' failure. Signed-off-by: Yan, Like Acked-by: Eddie Dong --- tools/acrnlog/acrnlog.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/acrnlog/acrnlog.c b/tools/acrnlog/acrnlog.c index 6f0ab8dd9..79f9103d7 100644 --- a/tools/acrnlog/acrnlog.c +++ b/tools/acrnlog/acrnlog.c @@ -127,7 +127,7 @@ static int get_cpu_num(void) struct hvlog_msg *hvlog_read_dev(struct hvlog_dev *dev) { int ret; - size_t len; + size_t len = 0; struct hvlog_msg *msg[2]; int msg_num; @@ -464,6 +464,8 @@ int main(int argc, char *argv[]) last = calloc(pcpu_num, sizeof(struct hvlog_data)); if (!last) { printf("Failed to allocate buf for last log buf\n"); + free(cur); + return -1; } num_cur = 0; @@ -499,7 +501,7 @@ int main(int argc, char *argv[]) } } - if (num_last && last) { + if (num_last) { while (1) { hvlog_dev_read_msg(last, pcpu_num); msg = get_min_seq_msg(last, pcpu_num); @@ -518,8 +520,7 @@ int main(int argc, char *argv[]) } free(cur); - if (last) - free(last); + free(last); return 0; }