Fix the coverity issue (Dereference after null check)
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-opp-client.c
index 9b635e6..3e83f72 100644 (file)
@@ -19,6 +19,7 @@
 #include <dlog.h>
 #include <string.h>
 #include <mime_type.h>
+#include <aul.h>
 #include <glib.h>
 #include <gio/gio.h>
 
@@ -574,7 +575,7 @@ void _bt_sending_files(void)
        GError *err = NULL;
        GDBusConnection *g_conn;
        GDBusProxy *client_proxy;
-       gchar *mime_type = NULL;
+       char mime_type[BT_MIME_TYPE_MAX_LEN + 1] = { 0 };
 
        if (sending_info == NULL)
                return;
@@ -589,7 +590,8 @@ void _bt_sending_files(void)
                                                BT_OBEX_OBJECT_PUSH_INTERFACE,
                                                NULL, &err);
                ret_if(client_proxy == NULL);
-               if (mime_type_get_mime_type(sending_info->file_name_array[file_offset], &mime_type) == MIME_TYPE_ERROR_NONE) {
+               if (aul_get_mime_from_file(sending_info->file_name_array[file_offset],
+                               mime_type, BT_MIME_TYPE_MAX_LEN) == AUL_R_OK) {
                                BT_DBG("MLME type = %s", mime_type);
 
                                /* For IOPT compliance, change "text/x-iMelody" to "audio/imelody"
@@ -616,7 +618,6 @@ void _bt_sending_files(void)
                if (err != NULL) {
                        BT_ERR("Calling SendFile failed: [%s]\n", err->message);
                        g_clear_error(&err);
-                       g_free(mime_type);
                        return;
                }
 
@@ -625,7 +626,6 @@ void _bt_sending_files(void)
                __bt_sending_release();
        }
 
-       g_free(mime_type);
        BT_DBG("-");
 }
 
@@ -812,6 +812,9 @@ int _bt_opp_client_push_files(int request_id, GDBusMethodInvocation *context,
        } else {
                /* Insert data in the queue */
                data = g_malloc0(sizeof(bt_sending_data_t));
+               if (data == NULL)
+                       return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
+
                data->file_path = g_new0(char *, file_count + 1);
                data->address = g_strdup(address);
                data->file_count = file_count;