glib's memory managed as below.
If any call to allocate memory fails, the application is terminated. This also means that there is no need to check if the call succeeded.
Change-Id: I0a47c563dda34a37d3936f94ef7f90fbfa679303
#include "media-util-db.h"
#define MS_SAFE_FREE(src) { if (src) {free(src); src = NULL; } }
-#define MS_MALLOC(src, size) { if (size > SIZE_MAX || size <= 0) src = NULL; \
- else { src = malloc(size); if (src) memset(src, 0x0, size); } }
-
#define MS_SQL_SAFE_FREE(x) {if (x != NULL) {sqlite3_free(x); x = NULL; } }
#define MS_STRING_VALID(str) ((str != NULL && strlen(str) > 0) ? true : false)
#define SAFE_STRLCPY(dst, src, n) g_strlcpy(dst, src, n);
return MS_MEDIA_ERR_INVALID_PARAMETER;
header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
- MS_MALLOC(buf, header_size);
+ buf = g_malloc0(header_size);
if ((recv_msg_size = recv(sockfd, buf, header_size, 0)) < 0) {
MSAPI_DBG_STRERROR("recv failed");
- MS_SAFE_FREE(buf);
+ g_free(buf);
return MS_MEDIA_ERR_IPC;
}
if (SQLITE_OK != ret) {
MSAPI_DBG_ERR("error when db open path[%s],ret[%d]", db_path, ret);
- MS_SAFE_FREE(db_path);
+ g_free(db_path);
*db_handle = NULL;
return MS_MEDIA_ERR_DB_INTERNAL;
}
- MS_SAFE_FREE(db_path);
+ g_free(db_path);
if (*db_handle == NULL) {
MSAPI_DBG_ERR("*db_handle is NULL");
MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_INVALID_PARAMETER, "ms_user_get_media_db_path failed");
if (!ms_ipc_is_valid_msg(db_path)) {
- MS_SAFE_FREE(db_path);
+ g_free(db_path);
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
send_msg.msg_type = MS_MSG_MEDIA_DB_MALFORMED;
SAFE_STRLCPY(send_msg.msg, db_path, sizeof(send_msg.msg));
- MS_SAFE_FREE(db_path);
+ g_free(db_path);
send_msg.uid = uid;
/*Create Socket*/
if (source_id)
g_source_destroy(source_id);
- MS_SAFE_FREE(req->path);
- MS_SAFE_FREE(req->userData);
- MS_SAFE_FREE(req);
+ g_free(req->path);
+ g_free(req->userData);
+ g_free(req);
}
len = g_queue_get_length(g_manage_queue);
req->isCanceled = true;
} else {
g_queue_pop_nth(g_manage_queue, i);
- MS_SAFE_FREE(req->path);
- MS_SAFE_FREE(req->userData);
- MS_SAFE_FREE(req);
+ g_free(req->path);
+ g_free(req->userData);
+ g_free(req);
}
return MS_MEDIA_ERR_NONE;
}
static int __media_dcm_request_async(int msg_type, const unsigned int request_id, const char *path, faceUserData *userData, uid_t uid)
{
- int len = 0;
dcmReq *dcm_req = NULL;
if (msg_type == DCM_MSG_REQUEST_CANCEL_FACE)
if (!g_manage_queue)
g_manage_queue = g_queue_new();
- dcm_req = calloc(1, sizeof(dcmReq));
- MSAPI_RETV_IF(!dcm_req, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ dcm_req = g_new0(dcmReq, 1);
dcm_req->msg_type = msg_type;
dcm_req->path = g_strdup(path);
dcm_req->uid = uid;
MSAPI_DBG("Enqueue");
- len = g_queue_get_length(g_manage_queue);
g_queue_push_tail(g_manage_queue, (gpointer)dcm_req);
/* directly request at first time */
- if (len == 0)
+ if (g_queue_get_length(g_manage_queue) == 1)
return __media_dcm_send_request();
return MS_MEDIA_ERR_NONE;
{
int exist = -1;
ms_user_storage_type_e storage_type = -1;
+ faceUserData *userData = NULL;
MSAPI_RETVM_IF(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- faceUserData *userData = (faceUserData*)malloc(sizeof(faceUserData));
- MSAPI_RETV_IF(!userData, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ userData = g_new0(faceUserData, 1);
userData->func = (FaceFunc)func;
userData->user_data = user_data;
ret = ms_user_get_internal_root_path(uid, &internal_path);
MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Fail get internal root path");
- MSAPI_RETVM_IF(internal_path == NULL, ret, "Fail get internal root path (NULL)");
path_len = strlen(internal_path);
ret = MS_MEDIA_ERR_INVALID_PARAMETER;
}
- MS_SAFE_FREE(internal_path);
+ g_free(internal_path);
return ret;
}
#define POWEROFF -1 /*This number uses for stopping Scannig thread*/
#define MS_SAFE_FREE(src) { if (src) {free(src); src = NULL; } }
-#define MS_MALLOC(src, size) { if (size > SIZE_MAX || size <= 0) src = NULL; \
- else { src = malloc(size); if (src) memset(src, 0x0, size); } }
#define MS_STRING_VALID(str) \
((str != NULL && strlen(str) > 0) ? true : false)
#define SAFE_STRLCPY(dst, src, n) g_strlcpy(dst, src, n);
func_array[func_index] = dlsym(func_handle, func_list[func_index]);
if (func_array[func_index] == NULL) {
MS_DBG_ERR("dlsym failed[%s]", func_list[func_index]);
- MS_SAFE_FREE(func_array);
+ g_free(func_array);
dlclose(func_handle);
return MS_MEDIA_ERR_INTERNAL;
char* folder_path = NULL;
folder_path = g_path_get_dirname(path);
ret = ms_get_folder_id(handle, storage_id, folder_path, &folder_id_folder);
- MS_SAFE_FREE(folder_path);
+ g_free(folder_path);
if(ret == MS_MEDIA_ERR_NONE) {
if (g_strcmp0(folder_id_media, folder_id_folder) == 0)
*modified = false;
} else
*modified = true;
- MS_SAFE_FREE(folder_id_folder);
+ g_free(folder_id_folder);
#endif
}
}
{
int ret = MS_MEDIA_ERR_NONE;
char **folder_list = NULL;
- char *sub_path = NULL;
int count = 0;
int i = 0;
ret = ((GET_NULL_SCAN_FOLDER_LIST)func_array[eGET_NULL_SCAN_FOLDER_LIST])(handle, stroage_id, path, &folder_list, &count); /*dlopen*/
MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "GET_NULL_SCAN_FOLDER_LIST failed [%d]", ret);
- *dir_array = g_array_new(FALSE, FALSE, sizeof(char*));
- if (count != 0) {
- for (i = 0; i < count; i++) {
- sub_path = strdup(folder_list[i]);
- g_array_append_val(*dir_array, sub_path);
- MS_SAFE_FREE(folder_list[i]);
- }
- }
+ *dir_array = g_array_sized_new(FALSE, FALSE, sizeof(char*), count);
+
+ for (i = 0; i < count; i++)
+ g_array_append_val(*dir_array, folder_list[i]);
+
MS_SAFE_FREE(folder_list);
MS_DBG_WARN("FIND DEV INFO : %s", name);
len = strlen(name + strlen(DEVICE_INFO_FILE));
if (len > 0) {
- *device_uuid = strndup(name + strlen(DEVICE_INFO_FILE), MS_UUID_SIZE -1);
+ *device_uuid = g_strndup(name + strlen(DEVICE_INFO_FILE), MS_UUID_SIZE -1);
MS_DBG_WARN("[%s][DEV ID: %s]", root_path, *device_uuid);
}
ret = ms_genarate_uuid(&id);
ret = ms_write_device_info(add_path , id);
if (ret == MS_MEDIA_ERR_NONE)
- *device_id = strdup(id);
+ *device_id = g_strdup(id);
}
} else {
- *device_id = strdup(id);
+ *device_id = g_strdup(id);
}
- MS_SAFE_FREE(id);
+ g_free(id);
return ret;
}
return ;
}
- type_str = strdup((char *)g_variant_get_type_string(parameters));
+ type_str = g_strdup((char *)g_variant_get_type_string(parameters));
if (!type_str) {
MS_DBG_ERR("Failed to get the type-string of message");
return ;
if (val_int == 2 || val_int == 3)
cb_func(usr_data);
- MS_SAFE_FREE(type_str);
+ g_free(type_str);
}
int ms_sys_set_poweroff_cb(power_off_cb user_callback, void *user_data)
res = vconf_get_str(key);
if (MS_STRING_VALID(res)) {
- *value = strdup(res);
+ *value = g_strdup(res);
MS_SAFE_FREE(res);
return true;
}
dir_path = g_path_get_dirname(full_path);
if (dir_path == NULL || strcmp(dir_path, ".") == 0) {
MS_DBG_ERR("getting directory path is failed : %s", full_path);
- MS_SAFE_FREE(dir_path);
+ g_free(dir_path);
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
ret = ms_user_get_internal_root_path(uid, &usr_path);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("ms_user_get_internal_root_path() fail");
- MS_SAFE_FREE(dir_path);
+ g_free(dir_path);
return MS_MEDIA_ERR_INTERNAL;
}
}
}
- MS_SAFE_FREE(dir_path);
- MS_SAFE_FREE(usr_path);
+ g_free(dir_path);
+ g_free(usr_path);
return ret;
}
static void __ms_trim_path(const char *input_path, char **output_path)
{
- char buf[4096] = {0,};
- char tmp[4096] = {0,};
+ char buf[4096] = {0, };
+ char tmp[4096] = {0, };
char *pos = NULL;
- memset(buf, 0, sizeof(buf));
SAFE_STRLCPY(buf, input_path, sizeof(buf));
while ((pos = strstr(buf, "//")) != NULL) {
#ifdef _USE_TVPD_MODE
if (g_strcmp0(tmp_path, org_path) != 0) {
MS_SAFE_FREE(tmp_path);
- MS_SAFE_FREE(org_path);
+ g_free(org_path);
MS_DBG_ERR("symbolic link(directory)");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
MS_SAFE_FREE(mediashared);
if (g_strcmp0(replace, org_path) != 0) {
MS_SAFE_FREE(tmp_path);
- MS_SAFE_FREE(org_path);
+ g_free(org_path);
MS_DBG_ERR("symbolic link(directory)");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
} else {
if (g_strcmp0(tmp_path, org_path) != 0) {
MS_SAFE_FREE(tmp_path);
- MS_SAFE_FREE(org_path);
+ g_free(org_path);
MS_DBG_ERR("symbolic link(directory)");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
}
#endif
MS_SAFE_FREE(tmp_path);
- MS_SAFE_FREE(org_path);
+ g_free(org_path);
if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
- memset(ignore_path, 0, sizeof(ignore_path));
snprintf(ignore_path, sizeof(ignore_path), "%s/%s", path, ignore_file);
if (g_file_test(ignore_path, G_FILE_TEST_EXISTS)) {
if (remain_path != NULL)
remain_len = strlen(remain_path);
- storage_path = strndup(start_path, strlen(start_path) - remain_len);
+ storage_path = g_strndup(start_path, strlen(start_path) - remain_len);
MS_DBG_SWARN("storage_path [%s]", storage_path);
MS_DBG_ERR("usb_device_get_device_list falied [%d]", err);
}
- MS_SAFE_FREE(storage_path);
+ g_free(storage_path);
#endif
return ret;
}
ret = MS_MEDIA_ERR_INTERNAL;
}
- MS_SAFE_FREE(db_path);
+ g_free(db_path);
return ret;
}
exit(0);
}
- argv1 = strdup(argv[1]);
- if (argv1 == NULL) {
- printf("[%d]Internal Memory Error\n", __LINE__);
- __print_help();
- exit(0);
- }
+ argv1 = argv[1];
mainloop = g_main_loop_new(NULL, FALSE);
exit(0);
}
} else if (argc == 3) {
- argv2 = strdup(argv[2]);
+ argv2 = argv[2];
if (strcmp(argv1, "-r") == 0) {
if ((argv2 != NULL) && (g_file_test(argv2, G_FILE_TEST_IS_DIR))) {
len = strlen(argv2);
scan_type = extract_data->msg_type;
noti_type = extract_data->noti_type;
- storage_id = strdup(extract_data->storage_id);
+ storage_id = g_strdup(extract_data->storage_id);
if (storage_id == NULL) {
MS_DBG_ERR("storage_id NULL");
ret = MS_MEDIA_ERR_INVALID_PARAMETER;
msc_send_result_partial(ret, MS_MSG_SCANNER_PARTIAL, extract_data->pid, extract_data->msg);
}
- MS_SAFE_FREE(update_path);
- MS_SAFE_FREE(extract_data);
- MS_SAFE_FREE(storage_id);
+ g_free(update_path);
+ g_free(extract_data);
+ g_free(storage_id);
__msc_del_cur_extract_item();
__msc_del_cancel_extract_item();
_POWEROFF:
__msc_resume_extract();
- MS_SAFE_FREE(update_path);
- MS_SAFE_FREE(extract_data);
- MS_SAFE_FREE(storage_id);
+ g_free(update_path);
+ g_free(extract_data);
+ g_free(storage_id);
if (handle) ms_disconnect_db(handle);
}
}
NEXT:
- MS_SAFE_FREE(update_path);
+ g_free(update_path);
if (power_off2) {
MS_DBG_ERR("power off");
msc_send_result(ret, extract_data);
}
- MS_SAFE_FREE(extract_data);
+ g_free(extract_data);
MS_DBG_WARN("STORAGE EXTRACT END[%d]", ret);
usleep(SCAN_SLEEP_TIME);
void msc_insert_exactor_request(int message_type, bool ins_status, const char *storage_id, const char *path, int pid, uid_t uid, ms_noti_type_e noti_type)
{
- ms_comm_msg_s *extract_data = NULL;
- MS_MALLOC(extract_data, sizeof(ms_comm_msg_s));
- if (extract_data == NULL) {
- MS_DBG_ERR("MS_MALLOC failed");
- return;
- }
+ ms_comm_msg_s *extract_data = g_new0(ms_comm_msg_s, 1);
extract_data->msg_type = message_type;
extract_data->pid = pid;
SAFE_STRLCPY(extract_data->storage_id, storage_id, sizeof(extract_data->storage_id));
if (message_type == MS_MSG_STORAGE_ALL || message_type == MS_MSG_STORAGE_PARTIAL || message_type == MS_MSG_STORAGE_INVALID) {
- g_async_queue_push(storage_extract_queue, GINT_TO_POINTER(extract_data));
+ g_async_queue_push(storage_extract_queue, extract_data);
MS_DBG("insert to storage exactor queue. msg_type [%d]", ins_status);
} else if (message_type == MS_MSG_DIRECTORY_SCANNING || message_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
- g_async_queue_push(folder_extract_queue, GINT_TO_POINTER(extract_data));
+ g_async_queue_push(folder_extract_queue, extract_data);
MS_DBG("insert to dir exactor queue. msg_type [%d]", ins_status);
} else {
MS_DBG_ERR("try to insert to exactor scan with msg_type [%d]", message_type);
- MS_SAFE_FREE(extract_data);
+ g_free(extract_data);
}
}
msg->msg_type = MS_MSG_EXTRACTOR_COMPLETE;
msc_send_result(MS_MEDIA_ERR_SCANNER_FORCE_STOP, msg);
}
- MS_SAFE_FREE(msg);
+ g_free(msg);
} else {
- g_async_queue_push(temp_queue, GINT_TO_POINTER(msg));
+ g_async_queue_push(temp_queue, msg);
}
}
len = g_async_queue_length(temp_queue);
for (j = 0; j < len; j++) {
msg = g_async_queue_pop(temp_queue);
if (msg)
- g_async_queue_push(storage_extract_queue, GINT_TO_POINTER(msg));
+ g_async_queue_push(storage_extract_queue, msg);
}
g_async_queue_unref(temp_queue);
static int __msc_set_extract_item(s_extract_item** item, const char* path, int pid)
{
s_extract_item* extract_item = *item;
- if (extract_item != NULL) {
- MS_SAFE_FREE(extract_item->path);
- extract_item->pid = -1;
- } else {
- extract_item = (s_extract_item*)malloc(sizeof(s_extract_item));
- if (extract_item == NULL) {
- MS_DBG_ERR("malloc item failed");
- return MS_MEDIA_ERR_INTERNAL;
- }
- memset(extract_item, 0, sizeof(s_extract_item));
- }
- extract_item->path = strdup(path);
+
+ if (!extract_item)
+ extract_item = g_new0(s_extract_item, 1);
+
+ g_free(extract_item->path);
+
+ extract_item->path = g_strdup(path);
extract_item->pid = pid;
+
*item = extract_item;
MS_DBG_SWARN("__msc_set_extract_item path[%s],pid[%d]", extract_item->path, extract_item->pid);
+
return MS_MEDIA_ERR_NONE;
}
static void __msc_del_extract_item(s_extract_item** item)
{
if (*item != NULL) {
- MS_SAFE_FREE((*item)->path);
- MS_SAFE_FREE(*item);
+ g_free((*item)->path);
+ g_free(*item);
}
}
if (g_extract_blocked_path != NULL) {
MS_DBG_SERR("g_extract_blocked_path is not NULL [%s]", g_extract_blocked_path);
- MS_SAFE_FREE(g_extract_blocked_path);
+ g_free(g_extract_blocked_path);
}
g_extract_blocked_path = g_strdup(blocked_path);
MS_DBG_FENTER();
g_mutex_lock(&extract_blocked_mutex);
+
if (blocked_path) {
if (g_extract_blocked_path && (0 == strncmp(blocked_path, g_extract_blocked_path, strlen(g_extract_blocked_path)))) {
MS_DBG_ERR("g_extract_blocked_path is deleted [%s]", g_extract_blocked_path);
if (storage_extract_queue) {
/*notify to storage extract thread*/
- MS_MALLOC(data, sizeof(ms_comm_msg_s));
- if (data != NULL) {
- data->pid = POWEROFF;
- g_async_queue_push(storage_extract_queue, GINT_TO_POINTER(data));
- }
+ data = g_new0(ms_comm_msg_s, 1);
+
+ data->pid = POWEROFF;
+ g_async_queue_push(storage_extract_queue, data);
}
if (folder_extract_queue) {
/*notify to folder extract thread*/
- MS_MALLOC(data, sizeof(ms_comm_msg_s));
- if (data != NULL) {
- data->pid = POWEROFF;
- g_async_queue_push(folder_extract_queue, GINT_TO_POINTER(data));
- }
+ data = g_new0(ms_comm_msg_s, 1);
+
+ data->pid = POWEROFF;
+ g_async_queue_push(folder_extract_queue, data);
}
}
{
if (g_extract_cancel_path != NULL) {
MS_DBG_WARN("g_extract_cancel_path is not NULL");
- MS_SAFE_FREE(g_extract_cancel_path);
+ g_free(g_extract_cancel_path);
}
- g_extract_cancel_path = strdup(cancel_path);
+ g_extract_cancel_path = g_strdup(cancel_path);
return MS_MEDIA_ERR_NONE;
}
/* make new array for storing directory */
dir_array = g_array_new(FALSE, FALSE, sizeof(char*));
- if (dir_array == NULL) {
- MS_DBG_ERR("g_array_new failed");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
/* add first direcotiry to directory array */
- new_start_path = strdup(start_path);
- if (new_start_path == NULL) {
- MS_DBG_ERR("strdup failed");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
+ new_start_path = g_strdup(start_path);
//MS_DBG_ERR("new start path [%s]", new_start_path);
g_array_append_val(dir_array, start_path);
ret = ms_check_scan_ignore(current_path, uid);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_SERR("%s is ignore", current_path);
- MS_SAFE_FREE(current_path);
+ g_free(current_path);
if (ret == MS_MEDIA_ERR_USB_UNMOUNTED)
goto STOP_SCAN;
else
ms_change_validity_item_batch(handle, storage_id, new_start_path, 1, 2, uid);
goto STOP_SCAN;
}
-
-
-
-
}
}
} else if (d->d_type == DT_DIR) {
if (scan_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
/* this request is recursive scanning */
/* add new directory to dir_array */
- new_path = strdup(path);
+ new_path = g_strdup(path);
g_array_append_val(dir_array, new_path);
if (ms_insert_folder(handle, storage_id, new_path, uid) != MS_MEDIA_ERR_NONE)
fd = -1;
}
- MS_SAFE_FREE(new_start_path);
+ g_free(new_start_path);
__msc_set_dir_scan_cur_path(NULL);
__msc_clear_file_list(dir_array);
/* make new array for storing directory */
dir_array = g_array_new(FALSE, FALSE, sizeof(char*));
- if (dir_array == NULL) {
- MS_DBG_ERR("g_array_new failed");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
/* add first direcotiry to directory array */
- new_start_path = strdup(start_path);
- if (new_start_path == NULL) {
- MS_DBG_ERR("strdup failed");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
+ new_start_path = g_strdup(start_path);
g_array_append_val(dir_array, start_path);
ms_insert_folder_end(uid);
} else if (d->d_type == DT_DIR) {
/* this request is recursive scanning */
/* add new directory to dir_array */
- new_path = strdup(path);
+ new_path = g_strdup(path);
g_array_append_val(dir_array, new_path);
if (ms_insert_folder(handle, storage_id, new_path, uid) != MS_MEDIA_ERR_NONE)
fd = -1;
}
- MS_SAFE_FREE(new_start_path);
+ g_free(new_start_path);
__msc_set_storage_scan_cur_path(NULL);
__msc_clear_file_list(dir_array);
g_array_remove_index(cur_dir_array, 0);
MS_DBG_SLOG("current_path = [%s]", current_path);
- new_path = strdup(current_path);
+ new_path = g_strdup(current_path);
g_array_append_val(dir_array, new_path);
- MS_SAFE_FREE(current_path);
+ g_free(current_path);
}
}
{
g_mutex_lock(&storage_scan_mutex2);
- if (NULL == scan_path) {
- MS_SAFE_FREE(g_storage_scan_path);
- } else {
- MS_SAFE_FREE(g_storage_scan_path);
- g_storage_scan_path = strdup(scan_path);
- }
+ g_free(g_storage_scan_path);
+ g_storage_scan_path = g_strdup(scan_path);
g_mutex_unlock(&storage_scan_mutex2);
}
if (remain_path != NULL)
remain_len = strlen(remain_path);
- storage_path = strndup(start_path, strlen(start_path) - remain_len);
+ storage_path = g_strndup(start_path, strlen(start_path) - remain_len);
g_mutex_lock(&dir_scan_mutex2);
if (NULL == g_dir_scan_path || NULL == storage_path) {
- MS_SAFE_FREE(storage_path);
+ g_free(storage_path);
g_mutex_unlock(&dir_scan_mutex2);
return MS_MEDIA_ERR_INTERNAL;
else
ret = strncmp(storage_path, g_dir_scan_path, storage_len);
- MS_SAFE_FREE(storage_path);
+ g_free(storage_path);
g_mutex_unlock(&dir_scan_mutex2);
return abs(ret);
{
g_mutex_lock(&dir_scan_mutex2);
- if (NULL == scan_path) {
- MS_SAFE_FREE(g_dir_scan_path);
- } else {
- MS_SAFE_FREE(g_dir_scan_path);
- g_dir_scan_path = strdup(scan_path);
- }
+ g_free(g_dir_scan_path);
+ g_dir_scan_path = g_strdup(scan_path);
g_mutex_unlock(&dir_scan_mutex2);
}
goto NEXT;
}
- storage_id = strdup(scan_data->storage_id);
- if (storage_id == NULL) {
- MS_DBG_ERR("storage_id NULL");
- ret = MS_MEDIA_ERR_INVALID_PARAMETER;
- goto NEXT;
- }
+ storage_id = g_strdup(scan_data->storage_id);
MS_DBG("path [%.*s], storage_id [%s], scan_type [%d]", MAX_MSG_SIZE, scan_data->msg, storage_id, scan_type);
scan_data->msg_type = MS_MSG_SCANNER_COMPLETE;
msc_send_result(ret, scan_data);
- MS_SAFE_FREE(scan_data);
- MS_SAFE_FREE(storage_id);
- MS_SAFE_FREE(folder_uuid);
+ g_free(scan_data);
+ g_free(storage_id);
+ g_free(folder_uuid);
g_directory_scan_processing2 = DIR_SCAN_NON_SCAN;
__msc_del_cur_scan_item();
} /*thread while*/
_POWEROFF:
- MS_SAFE_FREE(scan_data);
+ g_free(scan_data);
if (handle) ms_disconnect_db(handle);
return false;
}
update_path = g_strdup(scan_data->msg);
- if (!MS_STRING_VALID(update_path)) {
- MS_DBG_ERR("Invalid update_path");
- ret = MS_MEDIA_ERR_INVALID_PARAMETER;
- goto NEXT;
- }
ret = __msc_check_memory_status(uid);
if (ret != MS_MEDIA_ERR_NONE) {
NEXT:
__msc_del_blocked_path();
- MS_SAFE_FREE(update_path);
+ g_free(update_path);
if (power_off2) {
MS_DBG_ERR("power off");
scan_data->msg_type = MS_MSG_SCANNER_COMPLETE;
msc_send_result(ret, scan_data);
- MS_SAFE_FREE(scan_data);
+ g_free(scan_data);
MS_DBG_WARN("STORAGE SCAN END[%d]", ret);
} /*thread while*/
_POWEROFF:
- MS_SAFE_FREE(scan_data);
+ g_free(scan_data);
if (handle) ms_disconnect_db(handle);
return false;
char *data = NULL;
data = g_array_index(path_array , char*, 0);
g_array_remove_index(path_array, 0);
- MS_SAFE_FREE(data);
+ g_free(data);
}
g_array_free(path_array, FALSE);
path_array = NULL;
memset(buf, 0x0, MS_FILE_PATH_LEN_MAX);
/* This is an array for storing the path of insert datas*/
*path_array = g_array_new(FALSE, FALSE, sizeof(char *));
- if (*path_array == NULL) {
- MS_DBG_ERR("g_array_new failed");
- res = MS_MEDIA_ERR_OUT_OF_MEMORY;
- goto FREE_RESOURCE;
- }
/* read registering file path from stored file */
while (fgets(buf, MS_FILE_PATH_LEN_MAX, fp) != NULL) {
length = strlen(buf); /*the return value of function, strlen(), includes "\n" */
- path = strndup(buf, length - 1); /*copying except "\n" and strndup fuction adds "\0" at the end of the copying string */
+ path = g_strndup(buf, length - 1); /*copying except "\n" and strndup fuction adds "\0" at the end of the copying string */
/* check valid path */
ret = ms_check_ignore_dir(path, uid);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_SERR("invalide path : %s", path);
- MS_SAFE_FREE(path);
+ g_free(path);
continue;
}
/* insert getted path to the list */
- if (g_array_append_val(*path_array, path) == NULL) {
- MS_DBG_ERR("g_array_append_val failed");
- res = MS_MEDIA_ERR_OUT_OF_MEMORY;
- goto FREE_RESOURCE;
- }
+ g_array_append_val(*path_array, path);
}
if (fp) fclose(fp);
}
file_path = g_strdup(register_data->msg);
- if (file_path == NULL) {
- MS_DBG_ERR("file_path is NULL");
- goto FREE_RESOURCE;
- }
ret = __msc_make_file_list(file_path, &path_array, uid);
if (ret != MS_MEDIA_ERR_NONE) {
__msc_clear_file_list(path_array);
- MS_SAFE_FREE(file_path);
- MS_SAFE_FREE(register_data);
+ g_free(file_path);
+ g_free(register_data);
usleep(SCAN_SLEEP_TIME);
} /*thread while*/
_POWEROFF:
- MS_SAFE_FREE(file_path);
- MS_SAFE_FREE(register_data);
+ g_free(file_path);
+ g_free(register_data);
if (register_array) {
while (register_array->len != 0) {
msg_data = g_array_index(register_array , ms_comm_msg_s*, 0);
g_array_remove_index(register_array, 0);
- MS_SAFE_FREE(msg_data);
+ g_free(msg_data);
}
g_array_free(register_array, FALSE);
register_array = NULL;
static int __msc_set_scan_item(s_scan_item** item, const char* path, int pid)
{
s_scan_item* scan_item = *item;
- if (scan_item != NULL) {
- MS_SAFE_FREE(scan_item->path);
- scan_item->pid = -1;
- } else {
- scan_item = (s_scan_item*)malloc(sizeof(s_scan_item));
- if (scan_item == NULL) {
- MS_DBG_ERR("malloc item failed...");
- return MS_MEDIA_ERR_INTERNAL;
- }
- memset(scan_item, 0, sizeof(s_scan_item));
- }
- scan_item->path = strdup(path);
+ if (!scan_item)
+ scan_item = g_new0(s_scan_item, 1);
+
+ g_free(scan_item->path);
+
+ scan_item->path = g_strdup(path);
scan_item->pid = pid;
+
*item = scan_item;
MS_DBG_SWARN("path[%s],pid[%d]", scan_item->path, scan_item->pid);
+
return MS_MEDIA_ERR_NONE;
}
static void __msc_del_scan_item(s_scan_item** item)
{
if (*item != NULL) {
- MS_SAFE_FREE((*item)->path);
- MS_SAFE_FREE(*item);
+ g_free((*item)->path);
+ g_free(*item);
}
}
if (g_blocked_path2 != NULL) {
MS_DBG_SWARN("g_blocked_path is not NULL [%s]", g_blocked_path2);
- MS_SAFE_FREE(g_blocked_path2);
+ g_free(g_blocked_path2);
}
- g_blocked_path2 = strdup(blocked_path);
+ g_blocked_path2 = g_strdup(blocked_path);
g_mutex_unlock(&blocked_mutex2);
switch (scan_type) {
case MS_SCAN_STORAGE:
- g_async_queue_push(storage_queue2, GINT_TO_POINTER(recv_msg));
+ g_async_queue_push(storage_queue2, recv_msg);
break;
case MS_SCAN_DIRECTORY:
- g_async_queue_push(scan_queue2, GINT_TO_POINTER(recv_msg));
+ g_async_queue_push(scan_queue2, recv_msg);
break;
case MS_SCAN_REGISTER:
- g_async_queue_push(reg_queue2, GINT_TO_POINTER(recv_msg));
+ g_async_queue_push(reg_queue2, recv_msg);
break;
default:
MS_DBG_ERR("invalid parameter");
if (scan_queue2) {
/*notify to scannig thread*/
- MS_MALLOC(data, sizeof(ms_comm_msg_s));
- if (data != NULL) {
- data->pid = POWEROFF;
- msc_push_scan_request(MS_SCAN_DIRECTORY, data);
- } else {
- MS_DBG_ERR("memory allocation failed");
- }
+ data = g_new0(ms_comm_msg_s, 1);
+
+ data->pid = POWEROFF;
+ msc_push_scan_request(MS_SCAN_DIRECTORY, data);
}
if (reg_queue2) {
/*notify to register thread*/
- MS_MALLOC(data, sizeof(ms_comm_msg_s));
- if (data != NULL) {
- data->pid = POWEROFF;
- msc_push_scan_request(MS_SCAN_REGISTER, data);
- } else {
- MS_DBG_ERR("memory allocation failed");
- }
+ data = g_new0(ms_comm_msg_s, 1);
+
+ data->pid = POWEROFF;
+ msc_push_scan_request(MS_SCAN_REGISTER, data);
}
if (storage_queue2) {
/*notify to register thread*/
- MS_MALLOC(data, sizeof(ms_comm_msg_s));
- if (data != NULL) {
- data->pid = POWEROFF;
- msc_push_scan_request(MS_SCAN_STORAGE, data);
- } else {
- MS_DBG_ERR("memory allocation failed");
- }
+ data = g_new0(ms_comm_msg_s, 1);
+
+ data->pid = POWEROFF;
+ msc_push_scan_request(MS_SCAN_STORAGE, data);
}
}
if ((strcmp(msg->msg, cancel_path) == 0) && (pid == msg->pid)) {
msg->msg_type = MS_MSG_DIRECTORY_SCANNING_CANCEL;
msc_send_result(MS_MEDIA_ERR_SCANNER_FORCE_STOP, msg);
- MS_SAFE_FREE(msg);
+ g_free(msg);
} else {
- g_async_queue_push(temp_scan_queue, GINT_TO_POINTER(msg));
+ g_async_queue_push(temp_scan_queue, msg);
}
}
for (; j < len; j++) {
msg = g_async_queue_pop(temp_scan_queue);
if (msg)
- g_async_queue_push(scan_queue2, GINT_TO_POINTER(msg));
+ g_async_queue_push(scan_queue2, msg);
}
g_async_queue_unref(temp_scan_queue);
MS_DBG_WARN("end update scan_queue2");
msg->msg_type = MS_MSG_DIRECTORY_SCANNING_CANCEL;
msc_send_result(MS_MEDIA_ERR_SCANNER_FORCE_STOP, msg);
}
- MS_SAFE_FREE(msg);
+ g_free(msg);
} else {
- g_async_queue_push(temp_extract_queue, GINT_TO_POINTER(msg));
+ g_async_queue_push(temp_extract_queue, msg);
}
}
for (; j < len; j++) {
msg = g_async_queue_pop(temp_extract_queue);
if (msg)
- g_async_queue_push(folder_extract_queue, GINT_TO_POINTER(msg));
+ g_async_queue_push(folder_extract_queue, msg);
}
g_async_queue_unref(temp_extract_queue);
MS_DBG_WARN("end update folder_extract_queue");
sockfd = g_io_channel_unix_get_fd(src);
if (sockfd < 0) {
MS_DBG_ERR("sock fd is invalid!");
- return TRUE;
+ return G_SOURCE_CONTINUE;
}
- MS_MALLOC(recv_msg, sizeof(ms_comm_msg_s));
- if (recv_msg == NULL) {
- MS_DBG_ERR("MS_MALLOC failed");
- return TRUE;
- }
+ recv_msg = g_new0(ms_comm_msg_s, 1);
/* read() is blocked until media scanner sends message */
err = read(sockfd, recv_msg, sizeof(ms_comm_msg_s));
if (err < 0) {
MS_DBG_STRERROR("fifo read failed");
- MS_SAFE_FREE(recv_msg);
- return MS_MEDIA_ERR_INTERNAL;
+ g_free(recv_msg);
+ return G_SOURCE_CONTINUE;
}
if (strlen(recv_msg->msg) == 0 || strlen(recv_msg->msg) >= MAX_MSG_SIZE) {
MS_DBG_ERR("msg size is invlid");
- MS_SAFE_FREE(recv_msg);
- return TRUE;
+ g_free(recv_msg);
+ return G_SOURCE_CONTINUE;
}
if (strlen(recv_msg->storage_id) >= MS_UUID_SIZE) {
MS_DBG_ERR("storage_id size is invlid");
- MS_SAFE_FREE(recv_msg);
- return TRUE;
+ g_free(recv_msg);
+ return G_SOURCE_CONTINUE;
}
MS_DBG_SLOG("receive msg from [%d][%d] M[%.*s] S[%.*s]", recv_msg->pid, recv_msg->msg_type, MAX_MSG_SIZE, recv_msg->msg, MS_UUID_SIZE, recv_msg->storage_id);
{
MS_DBG_INFO("BULK INSERT");
/* request bulk insert*/
- g_async_queue_push(reg_queue2, GINT_TO_POINTER(recv_msg));
+ g_async_queue_push(reg_queue2, recv_msg);
}
break;
case MS_MSG_DIRECTORY_SCANNING:
{
/* this request from another apps */
/* set the scan data for scanning thread */
- g_async_queue_push(scan_queue2, GINT_TO_POINTER(recv_msg));
+ g_async_queue_push(scan_queue2, recv_msg);
}
break;
case MS_MSG_STORAGE_ALL:
case MS_MSG_STORAGE_INVALID:
{
/* this request from media-server */
- g_async_queue_push(storage_queue2, GINT_TO_POINTER(recv_msg));
+ g_async_queue_push(storage_queue2, recv_msg);
}
break;
case MS_MSG_DIRECTORY_SCANNING_CANCEL:
{
__msc_remove_request(scan_queue2, recv_msg);
msc_send_result(MS_MEDIA_ERR_SCANNER_FORCE_STOP, recv_msg);
- MS_SAFE_FREE(recv_msg);
+ g_free(recv_msg);
}
break;
default:
{
MS_DBG_ERR("THIS REQUEST IS INVALID %d", req_num);
- MS_SAFE_FREE(recv_msg);
+ g_free(recv_msg);
}
break;
}
/*Active flush */
malloc_trim(0);
- return TRUE;
+ return G_SOURCE_CONTINUE;
}
int msc_send_ready(void)
static void _power_off_cb(void* data)
{
- ms_comm_msg_s *scan_data;
- ms_comm_msg_s *reg_data;
+ ms_comm_msg_s *scan_data = NULL;
+ ms_comm_msg_s *reg_data = NULL;
MS_DBG_ERR("POWER OFF CB Begin");
if (scan_queue2) {
/*notify to scannig thread*/
- MS_MALLOC(scan_data, sizeof(ms_comm_msg_s));
- if (scan_data != NULL) {
- scan_data->pid = POWEROFF;
- g_async_queue_push(scan_queue2, GINT_TO_POINTER(scan_data));
- }
+ scan_data = g_new0(ms_comm_msg_s, 1);
+
+ scan_data->pid = POWEROFF;
+ g_async_queue_push(scan_queue2, scan_data);
}
if (reg_queue2) {
/*notify to register thread*/
- MS_MALLOC(reg_data, sizeof(ms_comm_msg_s));
- if (reg_data != NULL) {
- reg_data->pid = POWEROFF;
- g_async_queue_push(reg_queue2, GINT_TO_POINTER(reg_data));
- }
+ reg_data = g_new0(ms_comm_msg_s, 1);
+
+ reg_data->pid = POWEROFF;
+ g_async_queue_push(reg_queue2, reg_data);
}
if (storage_queue2) {
/*notify to register thread*/
- MS_MALLOC(reg_data, sizeof(ms_comm_msg_s));
- if (reg_data != NULL) {
- reg_data->pid = POWEROFF;
- g_async_queue_push(storage_queue2, GINT_TO_POINTER(reg_data));
- }
+ reg_data = g_new0(ms_comm_msg_s, 1);
+
+ reg_data->pid = POWEROFF;
+ g_async_queue_push(storage_queue2, reg_data);
}
if (storage_extract_queue) {
/*notify to storage extract thread*/
- MS_MALLOC(reg_data, sizeof(ms_comm_msg_s));
- if (reg_data != NULL) {
- reg_data->pid = POWEROFF;
- g_async_queue_push(storage_extract_queue, GINT_TO_POINTER(reg_data));
- }
+ reg_data = g_new0(ms_comm_msg_s, 1);
+
+ reg_data->pid = POWEROFF;
+ g_async_queue_push(storage_extract_queue, reg_data);
}
if (folder_extract_queue) {
/*notify to folder extract thread*/
- MS_MALLOC(reg_data, sizeof(ms_comm_msg_s));
- if (reg_data != NULL) {
- reg_data->pid = POWEROFF;
- g_async_queue_push(folder_extract_queue, GINT_TO_POINTER(reg_data));
- }
+ reg_data = g_new0(ms_comm_msg_s, 1);
+
+ reg_data->pid = POWEROFF;
+ g_async_queue_push(folder_extract_queue, reg_data);
}
if (g_main_loop_is_running(scanner_mainloop2)) g_main_loop_quit(scanner_mainloop2);
}
END:
- MS_SAFE_FREE(disc_type);
+ g_free(disc_type);
}
#endif
ms_set_folder_validity(handle, storage_id, start_path, 0, true, scan_data->uid);
- MS_SAFE_FREE(start_path);
+ g_free(start_path);
}
sync();
ret = ms_get_folder_id(handle, scan_data->storage_id, scan_data->msg, &folder_uuid);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("ms_get_folder_id failed");
- MS_SAFE_FREE(start_path);
+ g_free(start_path);
return ret;
}
ret = ms_send_dir_update_noti(scan_data->msg, folder_uuid, noti_type, scan_data->pid);
}
- MS_SAFE_FREE(folder_uuid);
+ g_free(folder_uuid);
return ret;
}
malloc_trim(0);
msc_send_result(ret, scan_data);
- MS_SAFE_FREE(scan_data);
+ g_free(scan_data);
MS_DBG_INFO("DIRECTORY SCAN END [%d]", ret);
} /*thread while*/
_POWEROFF:
- MS_SAFE_FREE(scan_data);
+ g_free(scan_data);
return false;
}
malloc_trim(0);
msc_send_result(ret, scan_data);
- MS_SAFE_FREE(scan_data);
+ g_free(scan_data);
MS_DBG_WARN("STORAGE SCAN END[%d]", ret);
} /*thread while*/
_POWEROFF:
- MS_SAFE_FREE(scan_data);
+ g_free(scan_data);
return FALSE;
}
while (fgets(buf, MS_FILE_PATH_LEN_MAX, fp) != NULL) {
/* Remove '\n' */
length = strlen(buf);
- path = strndup(buf, length - 1);
+ path = g_strndup(buf, length - 1);
/* check valid path */
ret = ms_check_ignore_dir(path, uid);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_SERR("invalide path : %s", path);
- MS_SAFE_FREE(path);
+ g_free(path);
continue;
}
malloc_trim(0);
msc_send_result(ret, register_data);
- MS_SAFE_FREE(register_data);
+ g_free(register_data);
MS_DBG_WARN("BULK REGISTER END [%d]", ret);
} /*thread while*/
_POWEROFF:
- MS_SAFE_FREE(register_data);
+ g_free(register_data);
return false;
}
ms_disconnect_db(handle);
msc_send_result(ret, scan_data);
- MS_SAFE_FREE(scan_data);
+ g_free(scan_data);
MS_DBG_INFO("META UPDATE END [%d]", ret);
switch (scan_type) {
case MS_SCAN_STORAGE:
- g_async_queue_push(storage_queue, GINT_TO_POINTER(recv_msg));
+ g_async_queue_push(storage_queue, recv_msg);
break;
case MS_SCAN_DIRECTORY:
- g_async_queue_push(scan_queue, GINT_TO_POINTER(recv_msg));
+ g_async_queue_push(scan_queue, recv_msg);
break;
case MS_SCAN_REGISTER:
- g_async_queue_push(reg_queue, GINT_TO_POINTER(recv_msg));
+ g_async_queue_push(reg_queue, recv_msg);
break;
default:
MS_DBG_ERR("invalid parameter");
if (scan_queue) {
/*notify to scannig thread*/
- MS_MALLOC(data, sizeof(ms_comm_msg_s));
- if (data != NULL) {
- data->pid = POWEROFF;
- msc_push_scan_request(MS_SCAN_DIRECTORY, data);
- } else {
- MS_DBG_ERR("memory allocation failed");
- }
+ data = g_new0(ms_comm_msg_s, 1);
+
+ data->pid = POWEROFF;
+ msc_push_scan_request(MS_SCAN_DIRECTORY, data);
}
if (reg_queue) {
/*notify to register thread*/
- MS_MALLOC(data, sizeof(ms_comm_msg_s));
- if (data != NULL) {
- data->pid = POWEROFF;
- msc_push_scan_request(MS_SCAN_REGISTER, data);
- } else {
- MS_DBG_ERR("memory allocation failed");
- }
+ data = g_new0(ms_comm_msg_s, 1);
+
+ data->pid = POWEROFF;
+ msc_push_scan_request(MS_SCAN_REGISTER, data);
}
if (storage_queue) {
/*notify to register thread*/
- MS_MALLOC(data, sizeof(ms_comm_msg_s));
- if (data != NULL) {
- data->pid = POWEROFF;
- msc_push_scan_request(MS_SCAN_STORAGE, data);
- } else {
- MS_DBG_ERR("memory allocation failed");
- }
+ data = g_new0(ms_comm_msg_s, 1);
+
+ data->pid = POWEROFF;
+ msc_push_scan_request(MS_SCAN_STORAGE, data);
}
}
msg = g_async_queue_pop(scan_queue);
if ((g_strcmp0(msg->msg, recv_msg->msg) == 0) && (recv_msg->pid == msg->pid)) {
MS_DBG("Find request. Remove it");
- MS_SAFE_FREE(msg);
+ g_free(msg);
} else {
- g_async_queue_push(temp_scan_queue, GINT_TO_POINTER(msg));
+ g_async_queue_push(temp_scan_queue, msg);
}
}
g_async_queue_unref(scan_queue);
sockfd = g_io_channel_unix_get_fd(src);
MS_DBG_RETVM_IF(sockfd < 0, G_SOURCE_CONTINUE, "sock fd is invalid!");
- MS_MALLOC(recv_msg, sizeof(ms_comm_msg_s));
- MS_DBG_RETVM_IF(!recv_msg, G_SOURCE_CONTINUE, "MS_MALLOC failed");
+ recv_msg = g_new0(ms_comm_msg_s, 1);
/* read() is blocked until media scanner sends message */
err = read(sockfd, recv_msg, sizeof(ms_comm_msg_s));
if (err < 0) {
MS_DBG_STRERROR("fifo read failed");
- MS_SAFE_FREE(recv_msg);
+ g_free(recv_msg);
return G_SOURCE_CONTINUE;
}
if (strlen(recv_msg->msg) == 0 || strlen(recv_msg->msg) >= MAX_MSG_SIZE) {
MS_DBG_ERR("msg size is invlid");
- MS_SAFE_FREE(recv_msg);
+ g_free(recv_msg);
return G_SOURCE_CONTINUE;
}
if (strlen(recv_msg->storage_id) >= MS_UUID_SIZE) {
MS_DBG_ERR("storage_id size is invlid");
- MS_SAFE_FREE(recv_msg);
+ g_free(recv_msg);
return G_SOURCE_CONTINUE;
}
break;
case MS_MSG_DIRECTORY_SCANNING_CANCEL:
msc_remove_dir_scan_request(recv_msg);
- MS_SAFE_FREE(recv_msg);
+ g_free(recv_msg);
break;
case MS_MSG_STORAGE_META:
msc_metadata_update_thread(recv_msg);
break;
default:
MS_DBG_ERR("THIS REQUEST IS INVALID %d", recv_msg->msg_type);
- MS_SAFE_FREE(recv_msg);
+ g_free(recv_msg);
break;
}
if (error)
g_error_free(error);
- MS_SAFE_FREE(db_path);
+ g_free(db_path);
MS_DBG_ERR("[MEDIA DB RESET END]");
static int __ms_dcm_recv_msg(int sock, dcmMsg *msg)
{
int recv_msg_len = 0;
- unsigned char *buf = NULL;
-
- MS_MALLOC(buf, sizeof(dcmMsg));
- MS_DBG_RETV_IF(!buf, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ unsigned char *buf = g_malloc0(sizeof(dcmMsg));
if ((recv_msg_len = recv(sock, buf, sizeof(dcmMsg), 0)) < 0) {
MS_DBG_STRERROR("recv failed");
- MS_SAFE_FREE(buf);
+ g_free(buf);
return MS_MEDIA_ERR_IPC;
}
memcpy(msg, buf, sizeof(dcmMsg));
if (strlen(msg->msg) >= MAX_FILEPATH_LEN) {
MS_DBG_ERR("msg size is invlid[%zu]", strlen(msg->msg));
- MS_SAFE_FREE(buf);
+ g_free(buf);
return MS_MEDIA_ERR_IPC;
}
- MS_SAFE_FREE(buf);
+ g_free(buf);
MS_DBG("msg_type [%d]", msg->msg_type);
if (client_sock <= 0 || !recv_msg) {
MS_DBG_ERR("client sock is below 0 or recv msg is NULL");
- MS_SAFE_FREE(req->recv_msg);
- MS_SAFE_FREE(req);
+ g_free(req->recv_msg);
+ g_free(req);
return G_SOURCE_CONTINUE;
}
close(client_sock);
- MS_SAFE_FREE(req->recv_msg);
- MS_SAFE_FREE(req);
+ g_free(req->recv_msg);
+ g_free(req);
return G_SOURCE_CONTINUE;
}
MS_DBG_STRERROR("sendto failed");
close(client_sock);
- MS_SAFE_FREE(req->recv_msg);
- MS_SAFE_FREE(req);
+ g_free(req->recv_msg);
+ g_free(req);
return G_SOURCE_CONTINUE;
}
struct sockaddr_un client_addr;
unsigned int client_addr_len;
dcmMsg *recv_msg = NULL;
+ dcmRequest *dcm_req = NULL;
int sock = -1;
int client_sock = -1;
MS_DBG("Client[%d] is accepted", client_sock);
- recv_msg = calloc(1, sizeof(dcmMsg));
- if (!recv_msg) {
- MS_DBG_ERR("Failed to allocate memodry");
- goto ERROR;
- }
+ recv_msg = g_new0(dcmMsg, 1);
if (__ms_dcm_recv_msg(client_sock, recv_msg) < 0) {
MS_DBG_ERR("__ms_dcm_recv_msg failed ");
goto ERROR;
}
- dcmRequest *dcm_req = NULL;
-
- MS_MALLOC(dcm_req, sizeof(dcmRequest));
- if (!dcm_req) {
- MS_DBG_ERR("Failed to create request element");
- goto ERROR;
- }
+ dcm_req = g_new0(dcmRequest, 1);
dcm_req->client_sock = client_sock;
dcm_req->recv_msg = recv_msg;
MS_DBG("Sent Refuse msg from %.*s", MAX_FILEPATH_LEN, recv_msg->msg);
close(client_sock);
- MS_SAFE_FREE(dcm_req->recv_msg);
- MS_SAFE_FREE(dcm_req);
+ g_free(dcm_req->recv_msg);
+ g_free(dcm_req);
return G_SOURCE_CONTINUE;
}
ERROR:
close(client_sock);
- MS_SAFE_FREE(recv_msg);
+ g_free(recv_msg);
return G_SOURCE_CONTINUE;
}
if (mount_path != NULL && mount_uuid != NULL) {
/*CHECK DB HERE */
- uuid = strndup(mount_uuid, strlen(mount_uuid));
+ uuid = g_strndup(mount_uuid, strlen(mount_uuid));
ret = ms_check_db_upgrade(handle, uid);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("ms_check_db_upgrade failed");
}
ERROR:
- MS_SAFE_FREE(storage_path);
- MS_SAFE_FREE(uuid);
+ g_free(storage_path);
+ g_free(uuid);
ms_disconnect_db(handle);
}
ERROR:
- MS_SAFE_FREE(storage_id);
- MS_SAFE_FREE(storage_path);
+ g_free(storage_id);
+ g_free(storage_path);
ms_disconnect_db(handle);
}
mount_path = usb_device_get_mountpath(device);
if (mount_path != NULL) {
MS_DBG_SWARN("mount_path [%s]", mount_path);
- storage_path = strdup(mount_path);
+ storage_path = g_strdup(mount_path);
g_array_append_val(*added_list, storage_path);
}
} else {
mount_path = usb_device_get_mountpath(device);
if (mount_path != NULL) {
MS_DBG_SWARN("mount_path [%s]", mount_path);
- storage_path = strdup(mount_path);
+ storage_path = g_strdup(mount_path);
g_array_append_val(*added_list, storage_path);
}
} else {
ret = ms_insert_storage(handle, device_uuid, mounted_path, uid);
scan_type = MS_SCAN_ALL;
- storage_id = strdup(device_uuid);
+ storage_id = g_strdup(device_uuid);
MS_SAFE_FREE(device_uuid);
} else {
if (ret == 0) {
if (validity == 1) {
MS_DBG_ERR("This storage is already updated.");
- MS_SAFE_FREE(db_storage_path);
+ g_free(db_storage_path);
continue;
}
ms_set_folder_scan_status(handle, storage_id, NULL, MS_DIR_SCAN_NONE, uid);
scan_type = MS_SCAN_PART;
- MS_SAFE_FREE(db_storage_path);
+ g_free(db_storage_path);
} else {
/* there is no information of this storage in Media DB */
MS_DBG_SWARN("insert storage %s", mounted_path);
MS_DBG_ERR("error : ms_insert_folder failed");
ms_send_storage_otg_scan_request(mounted_path, storage_id, scan_type, uid);
- MS_SAFE_FREE(storage_id);
+ g_free(storage_id);
}
for (i = 0; i < count; i++) {
mounted_path = g_array_index(added_list, char*, 0);
- MS_SAFE_FREE(mounted_path);
+ g_free(mounted_path);
g_array_remove_index(added_list, 0);
}
}
END:
- MS_SAFE_FREE(disc_type);
- MS_SAFE_FREE(disc_path);
+ g_free(disc_type);
+ g_free(disc_path);
g_free(storage_path);
}
#endif
MS_DBG_WARN("language is changed but do not update meta data");
}
- MS_SAFE_FREE(priv_lang);
+ g_free(priv_lang);
if (MS_STRING_VALID(lang))
- priv_lang = strdup(lang);
+ priv_lang = g_strdup(lang);
- MS_SAFE_FREE(lang);
+ g_free(lang);
}
#endif
if (MS_STRING_VALID(lang)) {
MS_DBG("Set language change cb [%s]", lang);
- priv_lang = strdup(lang);
+ priv_lang = g_strdup(lang);
err = vconf_notify_key_changed(VCONFKEY_LANGSET, (vconf_callback_fn) __ms_change_lang_vconf_cb, NULL);
if (err == -1)
MS_DBG_ERR("add call back function for event %s fails", VCONFKEY_LANGSET);
}
- MS_SAFE_FREE(lang);
+ g_free(lang);
#endif
#ifdef _USE_SENIOR_MODE
}
END:
- MS_SAFE_FREE(disc_type);
- MS_SAFE_FREE(disc_path);
- MS_SAFE_FREE(storage_path);
+ g_free(disc_type);
+ g_free(disc_path);
+ g_free(storage_path);
return MS_MEDIA_ERR_NONE;
}
ms_req_owner_data **_data = (ms_req_owner_data **) data;
close((*_data)->client_sockfd);
- MS_SAFE_FREE((*_data)->req_path);
- MS_SAFE_FREE(*_data);
+ g_free((*_data)->req_path);
+ g_free(*_data);
MS_DBG("DELETE OWNER");
}
if (!owner_list) {
owner_list = g_array_new(FALSE, FALSE, sizeof(ms_req_owner_data *));
- MS_DBG_RETVM_IF(!owner_list, MS_MEDIA_ERR_OUT_OF_MEMORY, "g_array_new failed");
g_array_set_clear_func(owner_list, __destroy_owner_data);
}
/* store pid and client address */
- MS_MALLOC(owner_data, sizeof(ms_req_owner_data));
- MS_DBG_RETVM_IF(!owner_data, MS_MEDIA_ERR_OUT_OF_MEMORY, "MS_MALLOC failed");
+ owner_data = g_new0(ms_req_owner_data, 1);
owner_data->pid = pid;
owner_data->client_sockfd = client_sock;
int ms_send_storage_scan_request(const char *root_path, const char *storage_id, ms_dir_scan_type_t scan_type, uid_t uid)
{
- ms_comm_msg_s scan_msg = { 0, };
+ ms_comm_msg_s scan_msg = {0, };
MS_DBG_RETVM_IF(uid == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid UID");
memset(&scan_msg, 0, sizeof(scan_msg));
int validity = 0;
ms_dir_scan_type_t scan_type = MS_SCAN_ALL;
char *storage_path = NULL;
- char* storage_id = strdup("familytv");
- char* path = MEDIA_ROOT_PATH_SENIOR_MODE;
+ const char* storage_id = g_strdup("familytv");
+ const char* path = MEDIA_ROOT_PATH_SENIOR_MODE;
ms_sys_get_uid(&uid);
}
scan_type = MS_SCAN_PART;
- MS_SAFE_FREE(storage_path);
+ g_free(storage_path);
} else {
/* there is no information of this storage in Media DB */
MS_DBG_SWARN("##[senior mode]insert storage %s", path);
MS_DBG_ERR("##[senior mode]error : ms_insert_folder failed");
ms_send_storage_otg_scan_request(path, storage_id, scan_type, uid);
- MS_SAFE_FREE(storage_id);
+ g_free(storage_id);
return ret;
}
unsigned char *buf = NULL;
unsigned int header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
- MS_MALLOC(buf, header_size);
- MS_DBG_RETV_IF(!buf, MS_MEDIA_ERR_OUT_OF_MEMORY);
+ buf = g_malloc0(header_size);
while (header_size > 0) {
if ((recv_len = recv(sock, buf + recv_pos, header_size, 0)) < 0) {
MS_DBG_STRERROR("recv failed");
- MS_SAFE_FREE(buf);
+ g_free(buf);
return MS_MEDIA_ERR_IPC;
}
header_size -= recv_len;
recv_pos = 0;
memcpy(msg, buf, header_size);
- MS_SAFE_FREE(buf);
+ g_free(buf);
MS_DBG("status[%d]", msg->status);
MS_DBG_RETV_IF(msg->thumb_size == 0, MS_MEDIA_ERR_NONE);
remain_size = msg->thumb_size;
- MS_MALLOC(buf, remain_size);
- MS_DBG_RETV_IF(!buf, MS_MEDIA_ERR_OUT_OF_MEMORY);
+
+ buf = g_malloc0(remain_size);
while (remain_size > 0) {
if ((recv_len = recv(sock, buf + recv_pos, remain_size, 0)) < 0) {
MS_DBG_STRERROR("recv failed");
- MS_SAFE_FREE(buf);
+ g_free(buf);
return MS_MEDIA_ERR_IPC;
}
fsync(sock);
remain_size -= recv_len;
}
- MS_SAFE_FREE(msg->thumb_data);
+ g_free(msg->thumb_data);
- MS_MALLOC(msg->thumb_data, (unsigned int)(msg->thumb_size));
- if (msg->thumb_data) {
- memcpy(msg->thumb_data, buf, msg->thumb_size);
- } else {
- MS_SAFE_FREE(buf);
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
+ msg->thumb_data = g_memdup(buf, msg->thumb_size);
- MS_SAFE_FREE(buf);
+ g_free(buf);
return MS_MEDIA_ERR_NONE;
}
MS_DBG_SLOG("Basic Size[%d] org_path[%s] dst_path[%s] thumb_data[%d]", header_size, req_msg->org_path, req_msg->dst_path, req_msg->thumb_size);
size = header_size + req_msg->thumb_size;
- MS_MALLOC(*buf, size);
- MS_DBG_RETV_IF(!(*buf), MS_MEDIA_ERR_OUT_OF_MEMORY);
+
+ *buf = g_malloc0(size);
memcpy(*buf, req_msg, header_size);
+
if (req_msg->thumb_size > 0)
memcpy((*buf) + header_size, req_msg->thumb_data, req_msg->thumb_size);
if (send(sock, buf, buf_size, 0) < 0) {
MS_DBG_STRERROR("send failed");
- MS_SAFE_FREE(buf);
+ g_free(buf);
close(sock);
return FALSE;
}
- MS_SAFE_FREE(buf);
+ g_free(buf);
MS_DBG_SLOG("Sending msg to thumbnail server is successful");
if (recv_msg->msg_type == THUMB_REQUEST_KILL_SERVER) {
if (client_sock <= 0 || !recv_msg) {
MS_DBG_ERR("client sock is below 0 or recv msg is NULL");
- MS_SAFE_FREE(req->recv_msg);
- MS_SAFE_FREE(req);
+ g_free(req->recv_msg);
+ g_free(req);
return G_SOURCE_CONTINUE;
}
close(client_sock);
- MS_SAFE_FREE(buf);
- MS_SAFE_FREE(req->recv_msg);
- MS_SAFE_FREE(req);
+ g_free(buf);
+ g_free(req->recv_msg);
+ g_free(req);
return G_SOURCE_CONTINUE;
}
}
close(client_sock);
- MS_SAFE_FREE(buf);
- MS_SAFE_FREE(req->recv_msg);
- MS_SAFE_FREE(req);
+ g_free(buf);
+ g_free(req->recv_msg);
+ g_free(req);
MS_SAFE_FREE(res_msg.thumb_data);
return G_SOURCE_CONTINUE;
MS_DBG("Client[%d] is accepted", client_sock);
- recv_msg = calloc(1, sizeof(thumbMsg));
- if (!recv_msg) {
- MS_DBG_ERR("Failed to allocate memory");
- close(client_sock);
- return G_SOURCE_CONTINUE;
- }
+ recv_msg = g_new0(thumbMsg, 1);
if (__ms_thumb_recv_msg(client_sock, recv_msg) < 0) {
MS_DBG_ERR("_ms_thumb_recv_msg failed ");
goto ERROR;
}
- MS_MALLOC(thumb_req, sizeof(thumbRequest));
- if (!thumb_req) {
- MS_DBG_ERR("Failed to create request element");
- goto ERROR;
- }
+ thumb_req = g_new0(thumbRequest, 1);
thumb_req->client_sock = client_sock;
thumb_req->recv_msg = recv_msg;
else
MS_DBG("Sent Refuse msg from %s", recv_msg->org_path);
- MS_SAFE_FREE(buf);
+ g_free(buf);
goto ERROR;
}
return G_SOURCE_CONTINUE;
ERROR:
close(client_sock);
- MS_SAFE_FREE(recv_msg->thumb_data);
- MS_SAFE_FREE(recv_msg);
- MS_SAFE_FREE(thumb_req);
+ g_free(recv_msg->thumb_data);
+ g_free(recv_msg);
+ g_free(thumb_req);
return G_SOURCE_CONTINUE;
}