deviced-input: Add a handling case for memory allocation failure 35/310435/2 accepted/tizen_unified_dev accepted/tizen/unified/20240502.105909 accepted/tizen/unified/dev/20240620.000236 accepted/tizen/unified/toolchain/20240507.011900 accepted/tizen/unified/x/20240503.091210 accepted/tizen/unified/x/asan/20240625.093052
authorYunhee Seo <yuni.seo@samsung.com>
Mon, 29 Apr 2024 02:11:55 +0000 (11:11 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Tue, 30 Apr 2024 02:41:15 +0000 (11:41 +0900)
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 <yuni.seo@samsung.com>
src/deviced-input/deviced-input.c

index 517001df6fd6147f48815109e60ac5d99f4e3246..4adbd5d549fd3c4c25ce1fd7bb71fba1713fd1ad 100644 (file)
@@ -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)