From a1c6ffae391b14d6368c4352ea2e066b79e048a9 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Mon, 22 Feb 2021 11:31:09 +0900 Subject: [PATCH] Fix svace issues - memory: DIVISION_BY_ZERO - touchscreen: Resource leaks Change-Id: I13b2570a61cbeabc236cf0717c9fd056dd17cb19 Signed-off-by: Yunmi Ha --- hw/memory/memory.c | 7 +++++-- hw/touchscreen/touchscreen.c | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/hw/memory/memory.c b/hw/memory/memory.c index 45e6a5c..2defae7 100644 --- a/hw/memory/memory.c +++ b/hw/memory/memory.c @@ -74,8 +74,11 @@ static int memory_get_gem_info(const int pid, struct gem_info *info) temp = total_rss / (unsigned long)BYTES_PER_KBYTE; info->rss = (int)temp; - temp = (total_rss / (unsigned long)total_hcount) / (unsigned long)BYTES_PER_KBYTE; - info->pss = (int)temp; + if (total_hcount > 0) { + temp = (total_rss / (unsigned long)total_hcount) / (unsigned long)BYTES_PER_KBYTE; + info->pss = (int)temp; + } else + info->pss = 0; fclose(fp); diff --git a/hw/touchscreen/touchscreen.c b/hw/touchscreen/touchscreen.c index 319c37c..983cb8f 100644 --- a/hw/touchscreen/touchscreen.c +++ b/hw/touchscreen/touchscreen.c @@ -140,13 +140,13 @@ static int touchscreen_init(void **data) { hal_backend_touchscreen_funcs *touchscreen_funcs; + if (touchscreen_probe() < 0) + return -ENOTSUP; + touchscreen_funcs = calloc(1, sizeof(hal_backend_touchscreen_funcs)); if (!touchscreen_funcs) return -ENOMEM; - if (touchscreen_probe() < 0) - return -ENOTSUP; - touchscreen_funcs->get_state = touchscreen_get_state; touchscreen_funcs->set_state = touchscreen_set_state; -- 2.7.4