Skip to content

Commit 6f340f8

Browse files
lyan3jren1
authored andcommitted
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>
1 parent fb19b29 commit 6f340f8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tools/acrnlog/acrnlog.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static int get_cpu_num(void)
127127
struct hvlog_msg *hvlog_read_dev(struct hvlog_dev *dev)
128128
{
129129
int ret;
130-
size_t len;
130+
size_t len = 0;
131131
struct hvlog_msg *msg[2];
132132
int msg_num;
133133

@@ -464,6 +464,8 @@ int main(int argc, char *argv[])
464464
last = calloc(pcpu_num, sizeof(struct hvlog_data));
465465
if (!last) {
466466
printf("Failed to allocate buf for last log buf\n");
467+
free(cur);
468+
return -1;
467469
}
468470

469471
num_cur = 0;
@@ -499,7 +501,7 @@ int main(int argc, char *argv[])
499501
}
500502
}
501503

502-
if (num_last && last) {
504+
if (num_last) {
503505
while (1) {
504506
hvlog_dev_read_msg(last, pcpu_num);
505507
msg = get_min_seq_msg(last, pcpu_num);
@@ -518,8 +520,7 @@ int main(int argc, char *argv[])
518520
}
519521

520522
free(cur);
521-
if (last)
522-
free(last);
523+
free(last);
523524

524525
return 0;
525526
}

0 commit comments

Comments
 (0)