summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHwankyu Jhun <h.jhun@samsung.com>2017-06-22 02:31:48 (GMT)
committerHwankyu Jhun <h.jhun@samsung.com>2017-06-22 03:41:12 (GMT)
commit859e5fcc7a39adffce9b7e728a44857dc76cfbfe (patch)
treefc4c5926f76f8c8e76b1ebaa39a6f43c42de42c7
parent9bfe79698e344e96e3d2853b958abf46d313a0ac (diff)
downloadapplication-859e5fcc7a39adffce9b7e728a44857dc76cfbfe.zip
application-859e5fcc7a39adffce9b7e728a44857dc76cfbfe.tar.gz
application-859e5fcc7a39adffce9b7e728a44857dc76cfbfe.tar.bz2
Fix exception handling about out of memoryrefs/changes/36/135336/2
Change-Id: Id5199483bbc1260eb2aef30fd94c959f8889823f Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rwxr-xr-xapp_control/app_control.c66
1 files changed, 45 insertions, 21 deletions
diff --git a/app_control/app_control.c b/app_control/app_control.c
index 095c80d..d2ad6a0 100755
--- a/app_control/app_control.c
+++ b/app_control/app_control.c
@@ -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)