deviced-input: Add a handling case for memory allocation failure 37/310437/2 accepted/tizen_8.0_unified accepted/tizen/8.0/unified/20240502.163832
authorYunhee Seo <yuni.seo@samsung.com>
Mon, 29 Apr 2024 03:08:07 +0000 (12:08 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Tue, 30 Apr 2024 02:18:29 +0000 (11:18 +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: I2d37d5d6e13f3bce6ef9e6541d0334bc45c0232c
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)