aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/BluetoothGattCharacteristic.cpp16
-rw-r--r--src/BluetoothGattDescriptor.cpp2
2 files changed, 17 insertions, 1 deletions
diff --git a/src/BluetoothGattCharacteristic.cpp b/src/BluetoothGattCharacteristic.cpp
index 028013a9..a087ae68 100644
--- a/src/BluetoothGattCharacteristic.cpp
+++ b/src/BluetoothGattCharacteristic.cpp
@@ -147,6 +147,9 @@ std::vector<unsigned char> BluetoothGattCharacteristic::read_value (uint16_t off
GBytes *result_gbytes = g_variant_get_data_as_bytes(result_variant);
std::vector<unsigned char> result = from_gbytes_to_vector(result_gbytes);
+ /* free the gbytes array */
+ g_bytes_unref(result_gbytes);
+
return result;
}
@@ -177,6 +180,9 @@ bool BluetoothGattCharacteristic::write_value (
&error
);
+ /* freeing the GBytes allocated inside from_vector_to_gbytes function */
+ g_bytes_unref(arg_value_gbytes);
+
handle_error(error);
return result;
@@ -268,8 +274,16 @@ std::vector<unsigned char> BluetoothGattCharacteristic::get_value ()
{
GVariant *value_variant = gatt_characteristic1_get_value (object);
GBytes *value_gbytes = g_variant_get_data_as_bytes(value_variant);
+ std::vector<unsigned char> result;
+
+ try {
+ result = from_gbytes_to_vector(value_gbytes);
+ } catch (std::exception &e) {
+ g_bytes_unref(value_gbytes);
+ throw e;
+ }
- std::vector<unsigned char> result = from_gbytes_to_vector(value_gbytes);
+ g_bytes_unref(value_gbytes);
return result;
}
diff --git a/src/BluetoothGattDescriptor.cpp b/src/BluetoothGattDescriptor.cpp
index f3810bdf..ff5f804d 100644
--- a/src/BluetoothGattDescriptor.cpp
+++ b/src/BluetoothGattDescriptor.cpp
@@ -149,6 +149,8 @@ std::vector<unsigned char> BluetoothGattDescriptor::read_value (uint16_t offset)
std::vector<unsigned char> result = from_chars_to_vector(result_chars);
+ g_free(result_chars);
+
return result;
}