From: Yunhee Seo Date: Mon, 29 Apr 2024 02:11:55 +0000 (+0900) Subject: deviced-input: Add a handling case for memory allocation failure X-Git-Tag: accepted/tizen/unified/20240502.105909^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2139e59c3b8fc78ac1d58c802b10779dc50824af;p=platform%2Fcore%2Fsystem%2Fplugin%2Fdeviced-headless.git deviced-input: Add a handling case for memory allocation failure While parsing input event conf file, memory callocaion can fails. However, free handling code was omitted in the allocation failed case. To prevent memory leak, this is necessary. Change-Id: I658cba460e487f66fa861c42803b05090d268ba7 Signed-off-by: Yunhee Seo --- diff --git a/src/deviced-input/deviced-input.c b/src/deviced-input/deviced-input.c index 517001d..4adbd5d 100644 --- a/src/deviced-input/deviced-input.c +++ b/src/deviced-input/deviced-input.c @@ -773,7 +773,7 @@ static void parse_event_action_property(gpointer data, gpointer user_data) static int parse_event_action(const struct parse_result *result, void *data) { struct input_config *ic; - struct input_parse_event_action *input_event_action; + struct input_parse_event_action input_event_action; GHashTable *hash_table = (GHashTable *) data; if (!result || !result->props) @@ -784,28 +784,30 @@ static int parse_event_action(const struct parse_result *result, void *data) _D("Input section=%s", result->section); - input_event_action = calloc(1, sizeof(struct input_parse_event_action)); - if (!input_event_action) - return 0; - - input_event_action->ieu = calloc(1, sizeof(struct input_event_unit)); - if (!input_event_action->ieu) - return 0; + input_event_action.ieu = calloc(1, sizeof(struct input_event_unit)); + if (!input_event_action.ieu) + goto fail_mem_alloc; - input_event_action->hash_table_key_infos = hash_table; - g_list_foreach(result->props, parse_event_action_property, input_event_action); + input_event_action.hash_table_key_infos = hash_table; + g_list_foreach(result->props, parse_event_action_property, &input_event_action); - ic = find_input_config(input_event_action->ieu->keycode); + ic = find_input_config(input_event_action.ieu->keycode); if (!ic) { ic = calloc(1, sizeof(struct input_config)); if (!ic) - return -ENOMEM; - ic->keycode = input_event_action->ieu->keycode; + goto fail_mem_alloc; + ic->keycode = input_event_action.ieu->keycode; SYS_G_LIST_APPEND(g_input_config_list, ic); } - SYS_G_LIST_APPEND(ic->event_list, input_event_action->ieu); + SYS_G_LIST_APPEND(ic->event_list, input_event_action.ieu); return 0; + +fail_mem_alloc: + if (input_event_action.ieu) + free(input_event_action.ieu); + + return -ENOMEM; } int check_input_event_condition(const struct input_event_unit *ieu)