DD_LIST_FOREACH_SAFE should be used when there is node remove operation from list.
[platform/core/system/libstorage.git] / src / storage-external-dbus.c
index 92c4dc1..dcd1e9e 100755 (executable)
@@ -205,7 +205,7 @@ int storage_ext_get_list(dd_list **list)
 
 out:
        if (ret < 0)
-               storage_ext_release_list(list);
+               storage_ext_release_list(list); //LCOV_EXCL_LINE System Error
        g_variant_iter_free(iter);
        g_variant_unref(result);
        return ret;
@@ -320,19 +320,19 @@ int storage_ext_register_device_change(storage_ext_changed_cb func, void *data)
 
        callback = (struct storage_ext_callback *)malloc(sizeof(struct storage_ext_callback));
        if (!callback) {
-//LCOV_EXCL_START System Error
+               //LCOV_EXCL_START System Error
                _E("malloc() failed");
                return -ENOMEM;
-//LCOV_EXCL_STOP
+               //LCOV_EXCL_STOP
        }
 
        conn = get_dbus_connection();
        if (!conn) {
-//LCOV_EXCL_START System Error
+               //LCOV_EXCL_START System Error
                free(callback);
                _E("Failed to get dbus connection");
                return -EPERM;
-//LCOV_EXCL_STOP
+               //LCOV_EXCL_STOP
        }
 
        block_id = g_dbus_connection_signal_subscribe(conn,
@@ -346,9 +346,11 @@ int storage_ext_register_device_change(storage_ext_changed_cb func, void *data)
                        NULL,
                        NULL);
        if (block_id == 0) {
+               //LCOV_EXCL_START System Error
                free(callback);
                _E("Failed to subscrive bus signal");
                return -EPERM;
+               //LCOV_EXCL_STOP
        }
 
        callback->func = func;
@@ -365,6 +367,7 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func)
        GDBusConnection *conn;
        struct storage_ext_callback *callback;
        dd_list *elem;
+       dd_list *elem_n;
 
        if (!func)
                return;
@@ -377,7 +380,7 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func)
 //LCOV_EXCL_STOP
        }
 
-       DD_LIST_FOREACH(changed_list, elem, callback) {
+       DD_LIST_FOREACH_SAFE(changed_list, elem, elem_n, callback) {
                if (callback->func != func)
                        continue;
                if (callback->block_id > 0)
@@ -402,13 +405,18 @@ int storage_ext_get_device_info(int storage_id, storage_ext_device *info)
                return -ENODEV;
        }
 
-       g_variant_get(result, "(issssssisibii)",
-                       &info->type, &info->devnode, &info->syspath,
-                       &info->fs_usage, &info->fs_type,
-                       &info->fs_version, &info->fs_uuid,
-                       &info->readonly, &info->mount_point,
-                       &info->state, &info->primary,
-                       &info->flags, &info->storage_id);
+       if (g_variant_check_format_string(result, "(issssssisibii)", true)) {
+               g_variant_get(result, "(issssssisibii)",
+                               &info->type, &info->devnode, &info->syspath,
+                               &info->fs_usage, &info->fs_type,
+                               &info->fs_version, &info->fs_uuid,
+                               &info->readonly, &info->mount_point,
+                               &info->state, &info->primary,
+                               &info->flags, &info->storage_id);
+       } else {
+               _E("No storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE
+               return -ENODEV;
+       }
 
        g_variant_unref(result);