Fix exception handling about out of memory
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 22 Jun 2017 02:31:48 +0000 (11:31 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 22 Jun 2017 03:41:12 +0000 (12:41 +0900)
Change-Id: Id5199483bbc1260eb2aef30fd94c959f8889823f
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
app_control/app_control.c

index 095c80d..d2ad6a0 100755 (executable)
@@ -342,10 +342,12 @@ int app_control_get_operation(app_control_h app_control, char **operation)
                return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
 
        operation_value = aul_svc_get_operation(app_control->data);
-       if (operation_value != NULL)
-               *operation = strdup(operation_value);
-       else
-               *operation = NULL;
+       if (operation_value == NULL)
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+       *operation = strdup(operation_value);
+       if (*operation == NULL)
+               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
 
        return APP_CONTROL_ERROR_NONE;
 }
@@ -373,10 +375,12 @@ int app_control_get_uri(app_control_h app_control, char **uri)
                return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
 
        uri_value = aul_svc_get_uri(app_control->data);
-       if (uri_value != NULL)
-               *uri = strdup(uri_value);
-       else
-               *uri = NULL;
+       if (uri_value == NULL)
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+       *uri = strdup(uri_value);
+       if (*uri == NULL)
+               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
 
        return APP_CONTROL_ERROR_NONE;
 }
@@ -404,10 +408,12 @@ int app_control_get_mime(app_control_h app_control, char **mime)
                return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
 
        mime_value = aul_svc_get_mime(app_control->data);
-       if (mime_value != NULL)
-               *mime = strdup(mime_value);
-       else
-               *mime = NULL;
+       if (mime_value == NULL)
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+       *mime = strdup(mime_value);
+       if (*mime == NULL)
+               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
 
        return APP_CONTROL_ERROR_NONE;
 }
@@ -435,10 +441,12 @@ int app_control_get_category(app_control_h app_control, char **category)
                return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
 
        category_value = aul_svc_get_category(app_control->data);
-       if (category_value != NULL)
-               *category = strdup(category_value);
-       else
-               *category = NULL;
+       if (category_value == NULL)
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+       *category = strdup(category_value);
+       if (*category == NULL)
+               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
 
        return APP_CONTROL_ERROR_NONE;
 }
@@ -478,10 +486,12 @@ int app_control_get_app_id(app_control_h app_control, char **app_id)
                return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
 
        app_id_value = aul_svc_get_appid(app_control->data);
-       if (app_id_value != NULL)
-               *app_id = strdup(app_id_value);
-       else
-               *app_id = NULL;
+       if (app_id_value == NULL)
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+       *app_id = strdup(app_id_value);
+       if (*app_id == NULL)
+               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
 
        return APP_CONTROL_ERROR_NONE;
 }
@@ -957,6 +967,8 @@ int app_control_get_extra_data(app_control_h app_control, const char *key, char
        }
 
        *value = strdup(data_value);
+       if (*value == NULL)
+               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
 
        return APP_CONTROL_ERROR_NONE;
 }
@@ -990,14 +1002,26 @@ int app_control_get_extra_data_array(app_control_h app_control, const char *key,
                return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
 
        for (i = 0; i < array_data_length; i++) {
-               if (array_data[i] != NULL)
+               if (array_data[i] != NULL) {
                        array_data_clone[i] = strdup(array_data[i]);
+                       if (array_data_clone[i] == NULL)
+                               goto error_oom;
+               }
        }
 
        *value = array_data_clone;
        *length = array_data_length;
 
        return APP_CONTROL_ERROR_NONE;
+
+error_oom:
+       for (i = 0; i < array_data_length; i++) {
+               if (array_data_clone[i])
+                       free(array_data_clone[i]);
+       }
+       free(array_data_clone);
+
+       return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
 }
 
 int app_control_is_extra_data_array(app_control_h app_control, const char *key, bool *array)