Skip to content

Commit 048d72f

Browse files
chengangcacrnsi
authored andcommitted
tools: acrn-crashlog: fix some possible memory leak
This patch is to fix some possible memory leak issues, which are reported by static analysis tool. 1. free uptime in error case handling of function parse_uptime. 2. unmap f in error case handling of function _file_read_key_value. Tracked-On: #2917 Reviewed-by: Liu, Xinwu <xinwu.liu@intel.com> Reviewed-by: Zhi Jin <zhi.jin@intel.com> Signed-off-by: CHEN Gang <gang.c.chen@intel.com> Acked-by: Zhang Di <di.zhang@intel.com>
1 parent 46480f6 commit 048d72f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

tools/acrn-crashlog/acrnprobe/load_conf.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,14 +629,17 @@ static int parse_uptime(xmlNodePtr cur, struct sender_t *sender)
629629
else if (name_is(cur, "eventhours"))
630630
res = load_cur_content(cur, uptime, eventhours);
631631

632-
if (res)
632+
if (res) {
633+
free(uptime);
633634
return -1;
635+
}
634636

635637
cur = cur->next;
636638
}
637639
res = asprintf(&uptime->path, "%s/uptime", sender->outdir);
638640
if (res < 0) {
639641
LOGE("build string failed\n");
642+
free(uptime);
640643
return -1;
641644
}
642645
sender->uptime = uptime;

tools/acrn-crashlog/common/fsutils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,12 +686,12 @@ static ssize_t _file_read_key_value(char *value, const size_t limit,
686686
return -errno;
687687
if (!key) {
688688
errno = EINVAL;
689-
return -errno;
689+
goto unmap;
690690
}
691691

692692
if (op != 'l' && op != 'r') {
693693
errno = EINVAL;
694-
return -errno;
694+
goto unmap;
695695
}
696696

697697
if (op == 'l')

0 commit comments

Comments
 (0)