tinyb
tinyb copied to clipboard
BluetoothGattCharacteristic memory leaks
In function:
/* D-Bus method calls: */
std::vector<unsigned char> BluetoothGattCharacteristic::read_value (uint16_t offset)
{
GError *error = NULL;
GBytes *result_gbytes;
GVariantDict dict;
g_variant_dict_init(&dict, NULL);
if (offset != 0)
g_variant_dict_insert_value(&dict, "offset", g_variant_new_uint16(offset));
GVariant *variant = g_variant_dict_end(&dict);
gatt_characteristic1_call_read_value_sync(
object,
&result_gbytes,
variant,
NULL,
&error
);
handle_error(error);
std::vector<unsigned char> result = from_gbytes_to_vector(result_gbytes);
/* free the gbytes array */
g_bytes_unref(result_gbytes);
return result;
}
handle_error(error) called before g_bytes_unref(result_gbytes), in case of error result_gbytes will never be unrefed.
In function
bool BluetoothGattCharacteristic::write_value (
const std::vector<unsigned char> &arg_value, uint16_t offset)
{
GError *error = NULL;
bool result = true;
GBytes *arg_value_gbytes = from_vector_to_gbytes(arg_value);
GVariantDict dict;
g_variant_dict_init(&dict, NULL);
if (offset != 0)
g_variant_dict_insert_value(&dict, "offset", g_variant_new_uint16(offset));
GVariant *variant = g_variant_dict_end(&dict);
result = gatt_characteristic1_call_write_value_sync(
object,
arg_value_gbytes,
variant,
NULL,
&error
);
handle_error(error);
/* freeing the GBytes allocated inside from_vector_to_gbytes function */
g_bytes_unref(arg_value_gbytes);
return result;
}
handle_error(error) called before g_bytes_unref(arg_value_gbytes), in case if error arg_value_gbytes will never be unrefed.