Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

BluetoothGattCharacteristic memory leaks #154

Open
ghost opened this issue Dec 19, 2018 · 0 comments
Open

BluetoothGattCharacteristic memory leaks #154

ghost opened this issue Dec 19, 2018 · 0 comments

Comments

@ghost
Copy link

ghost commented Dec 19, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants