AnsweredAssumed Answered

Dynamic service memory leak

Question asked by Mateusz Wielgos on Feb 7, 2018
Latest reply on Feb 28, 2018 by Rodríguez

I am using KW41Z with version 2.2.0 of the SDK (framework v. 5.3.3, bluetooth v. 1.2.3).

 

There seems to be a memory leak with GattDbDynamic_AddCharacteristicDeclarationAndValue. If I create a service and a characteristic, remove both, and then re-create them, GattDbDynamic_AddCharacteristicDeclarationAndValue returns gBleOutOfMemory_c.

 

Another related issue that I see is that there seems to be no way to remove characteristic descriptors. GattDbDynamic_AddCharacteristicDescriptor exists but there is no remove counter-part. I assume that removing a characteristic (or service) should get rid of a descriptor but that is only my own assumption - documentation does not seem to be very explicit on the subject.

 

Here's a sample function demonstrating the memory leak.

bool_t Cdc_Start(void)

{

    static const uint8_t maxSize = 244;

    static uint8_t charValue[1] = { 0x00 };

 

    static bleUuid_t uuid_service_controller_data_channel = { .uuid128 = { 0x38, 0x93, 0xF0, 0x2D, 0x01, 0xAE, 0xC1, 0x8F, 0x3B, 0x45, 0x25, 0xE8, 0xB8, 0xD4, 0x57, 0x0C } };

    static bleUuid_t uuid_char_controller_data_channel = { .uuid128 = { 0x7A, 0x77, 0x8E, 0x8A, 0xB3, 0x8F, 0x59, 0x8F, 0x15, 0x4D, 0xCF, 0x1C, 0x32, 0x4A, 0x63, 0x5F } };

    static uint16_t service_controller_data_channel = -1;

    static uint16_t char_controller_data_channel = -1;

 

    service_controller_data_channel = -1;

    char_controller_data_channel = -1;

 

    bleResult_t resService1 = GattDbDynamic_AddPrimaryServiceDeclaration(

        gBleUuidType128_c,

        &uuid_service_controller_data_channel,

        &service_controller_data_channel

    );

 

    bleResult_t resChar1 = GattDbDynamic_AddCharacteristicDeclarationAndValue(

        gBleUuidType128_c,

        &uuid_char_controller_data_channel,

        gGattCharPropNotify_c,

        maxSize,

        sizeof(charValue),

        charValue,

        gPermissionNone_c,

        &char_controller_data_channel

    );

 

    bleResult_t resService2 = GattDbDynamic_RemoveCharacteristic(char_controller_data_channel);

 

    bleResult_t resChar2 = GattDbDynamic_RemoveService(service_controller_data_channel);

 

    bleResult_t resService3 = GattDbDynamic_AddPrimaryServiceDeclaration(

        gBleUuidType128_c,

        &uuid_service_controller_data_channel,

        &service_controller_data_channel

    );

 

    bleResult_t resChar3 = GattDbDynamic_AddCharacteristicDeclarationAndValue(

        gBleUuidType128_c,

        &uuid_char_controller_data_channel,

        gGattCharPropNotify_c,

        maxSize,

        sizeof(charValue),

        charValue,

        gPermissionNone_c,

        &char_controller_data_channel

    );

 

    if(resService1 == gBleSuccess_c && resService2 == gBleSuccess_c && resService3 == gBleSuccess_c && resChar1 == gBleSuccess_c && resChar2 == gBleSuccess_c && resChar3 == gBleSuccess_c)

    {

        printf("Good");

    }

    else

    {

        printf("Bad");

    }

 

    return TRUE;

}

Outcomes