Implement set / get volume logic from transport
[platform/core/connectivity/bluetooth-frwk.git] / bt-otp / bt-otpserver.c
index 80348d1..ae40cef 100644 (file)
@@ -609,7 +609,7 @@ static gboolean __server_data_received_cb(GIOChannel *chan, GIOCondition cond,
                return TRUE;
        }
 
-       BT_DBG("Received data length %d, remote_addr = %s", len, remote_addr);
+       BT_DBG("Received data length %zu, remote_addr = %s", len, remote_addr);
 
        if (!oacp_op->fp) {
                char file_path[BT_FILE_PATH_MAX_LEN] = {0, };
@@ -636,7 +636,7 @@ static gboolean __server_data_received_cb(GIOChannel *chan, GIOCondition cond,
        if (oacp_op->length_sofar <= oacp_op->length) {
                written = fwrite(buffer, 1, len, oacp_op->fp);
                oacp_op->length_sofar += written;
-               BT_DBG("written [%d], length_sofar [%lu], received_buff_len [%d], size [%lu]",
+               BT_DBG("written [%d], length_sofar [%u], received_buff_len [%zu], size [%u]",
                                        written, oacp_op->length_sofar, len, oacp_op->length);
        }
 
@@ -815,6 +815,9 @@ fail:
                                _bt_otp_start_write_on_fd();
                        else if (oacp_op->opcode == OACP_WRITE)
                                _bt_otp_start_read_on_fd();
+               } else {
+                       /* Close fd if oacp_op is NULL */
+                       close(fd);
                }
                g_dbus_method_invocation_return_value(invocation, NULL);
        }
@@ -1185,8 +1188,6 @@ void _bt_otp_create_new_object(uint32_t size, char *uuid)
        curr_obj_index = g_slist_length(otp_object_list) - 1;
        curr_obj_id = selected_object->id;
        object_id++;
-
-       free(uuid);
 }
 
 void _bt_otp_restore_old_object()
@@ -1221,7 +1222,7 @@ int _bt_otp_oacp_write_cb(char *value, int len, int offset,
        int opcode = value[0];
        uint32_t object_offset, length, object_size;
        uint8_t mode = 0;
-       char *uuid;
+       char *uuid = NULL;
        char absolute_file_path[BT_FILE_PATH_MAX_LEN] = {0, };
 
        BT_INFO("OACP Opcode 0x%d", opcode);
@@ -1255,6 +1256,7 @@ int _bt_otp_oacp_write_cb(char *value, int len, int offset,
 
                oacp_create = TRUE;
                _bt_otp_create_new_object(object_size, uuid);
+               g_free(uuid);
 
                if (oacp_create_timeout_id > 0)
                        g_source_remove(oacp_create_timeout_id);
@@ -1328,7 +1330,7 @@ int _bt_otp_oacp_write_cb(char *value, int len, int offset,
                if (opcode == OACP_WRITE)
                        mode = (uint8_t)value[9] & 0xFF;
 
-               BT_INFO("Offset = %lu, Length = %lu", object_offset, length, mode);
+               BT_INFO("Offset = %u, Length = %u", object_offset, length);
 
                if (oacp_op) {
                        if (otc_connection_status) {
@@ -1595,7 +1597,7 @@ int _bt_otp_olcp_write_cb(char *value, int len, int offset,
                                (uint64_t)(value[3] & 0xFF) << 16 |
                                (uint64_t)(value[2] & 0xFF) << 8  |
                                (uint64_t)(value[1] & 0xFF);
-               BT_INFO("Object ID [%llu]", object_id);
+               BT_INFO("Object ID [%llu]", (unsigned long long int)object_id);
                if (selected_object && selected_object->id == object_id)
                        goto fail;
 
@@ -1820,6 +1822,9 @@ int _bt_otp_read_cb(const char *obj_path, char **value, int *len, uint16_t offse
 
                *len = info->value_length - offset;
                *value = (char *)malloc(sizeof(char)*(*len));
+               if (*value == NULL)
+                       return BLUETOOTH_ATT_ERROR_INTERNAL;
+
                memcpy(*value, info->char_value, *len);
 
                return BLUETOOTH_ATT_ERROR_NONE;
@@ -1966,6 +1971,7 @@ void _bt_otp_gatt_char_property_changed_event(GVariant *msg,
                                } else {
                                        BT_ERR("Array Len 0");
                                }
+                               g_variant_unref(val);
                        } else {
                                BT_ERR("var==NULL");
                        }
@@ -2127,6 +2133,7 @@ void _bt_otp_device_property_event_filter(GDBusConnection *connection,
                        }
                }
        }
+       g_variant_unref(val);
 }
 
 int _bt_otp_init_event_receiver()