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 <like.yan@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Yan, Like 2018-05-14 14:26:29 +08:00 committed by Jack Ren
parent fb19b296ea
commit 6f340f8564
1 changed files with 5 additions and 4 deletions

View File

@ -127,7 +127,7 @@ static int get_cpu_num(void)
struct hvlog_msg *hvlog_read_dev(struct hvlog_dev *dev) struct hvlog_msg *hvlog_read_dev(struct hvlog_dev *dev)
{ {
int ret; int ret;
size_t len; size_t len = 0;
struct hvlog_msg *msg[2]; struct hvlog_msg *msg[2];
int msg_num; int msg_num;
@ -464,6 +464,8 @@ int main(int argc, char *argv[])
last = calloc(pcpu_num, sizeof(struct hvlog_data)); last = calloc(pcpu_num, sizeof(struct hvlog_data));
if (!last) { if (!last) {
printf("Failed to allocate buf for last log buf\n"); printf("Failed to allocate buf for last log buf\n");
free(cur);
return -1;
} }
num_cur = 0; num_cur = 0;
@ -499,7 +501,7 @@ int main(int argc, char *argv[])
} }
} }
if (num_last && last) { if (num_last) {
while (1) { while (1) {
hvlog_dev_read_msg(last, pcpu_num); hvlog_dev_read_msg(last, pcpu_num);
msg = get_min_seq_msg(last, pcpu_num); msg = get_min_seq_msg(last, pcpu_num);
@ -518,8 +520,7 @@ int main(int argc, char *argv[])
} }
free(cur); free(cur);
if (last) free(last);
free(last);
return 0; return 0;
} }