none
Bluetooth LE driver memory leaks RRS feed

  • Question

  • I develop an application that communicates with some sensor through Bluetooth Smart.

    I use a native c++, so code the following:

    // Register for noti:

    BLUETOOTH_GATT_EVENT_HANDLE registered_event_handle;

                hr = BluetoothGATTRegisterEvent(
                    le_device.get(),
                    EventType,
                    &EventParameterIn,
                    measurement_event,
                    (void*)registration.get(),
                    &registered_event_handle,
                    BLUETOOTH_GATT_FLAG_NONE);
                if (hr == S_OK)
                {
                    registration->set_event_handle(registered_event_handle);
                    registarations_.push_back(registration);
                }
                else
                {
                    std::wstring message;
                    Get_message_from_hresult(hr, message);
                }

    // data reading

    void measurement_event(BTH_LE_GATT_EVENT_TYPE event_type, PVOID event_out_parameter, PVOID context)
    {
        
        PBLUETOOTH_GATT_VALUE_CHANGED_EVENT ValueChangedEventParameters = (PBLUETOOTH_GATT_VALUE_CHANGED_EVENT)event_out_parameter;
        if (ValueChangedEventParameters->CharacteristicValue->DataSize == 0)
        {
            return;
        }

        ble_win::Registration::proc(
            (mcs_ble_win::Registration*)context,
            ValueChangedEventParameters->CharacteristicValue->Data,
            ValueChangedEventParameters->CharacteristicValue->DataSize);
    }

    Using poolmon.exe I determine memory leaks in driver with BthL tag. The spped of memory leakage is constant, i.e. if I run my app for 10 sec I get memory leakage 2 times less than if I run my app for 20 sec.

    How to investigate this problem in more specific details?

    Saturday, July 25, 2015 11:28 AM

Answers

All replies

  • what happens when the app is closed? does pool usage for the tag go down?

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Saturday, July 25, 2015 8:07 PM
  • Pool usage go down after rebooting PC or unpluging USB-Bluetuth dongle.

    Closing app has no any effect on pool usage.

    Saturday, July 25, 2015 8:27 PM
  • I tried the "Bluetooth Generic Attribute Profile - Heart Rate Service"sample application

    from here: https://code.msdn.microsoft.com/windowsapps/Bluetooth-Generic-5a99ef95

    That sample application behaves the same with pool usage. Pool usage grows during application is working. After application closes, pool usage doesn't go down.

    If I unplug USB-Bluetooth dongle or remove sensor from Windows, pool usage goes down.

    Obviously, rebooting the system frees pool.

    What could be the reason of memory leakage?

    Sunday, July 26, 2015 3:17 PM
  • it might not be a leak, the driver could be caching information. clearly it is being tracked, otherwise it wouldn't be freed when the device is removed.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by Ivan Chepiga Sunday, August 2, 2015 10:42 AM
    • Unmarked as answer by Ivan Chepiga Friday, February 12, 2016 7:39 PM
    Monday, July 27, 2015 1:02 AM
  • Is  there any way to fix that problem? During 8-hours test BlthL driver "eats" all RAM and PC goes down.

    I agree it is not a leak, but it looks like a bug. Why does driver cache data which is overwritten many times?

    To free memory I have to eather remove device from the system or reboot PC.

    Another problem is my app cant work more than 8 hours.

    Monday, July 27, 2015 6:51 AM
  • I just ran my application to the point where it crashed my PC. I ran it from 6 in the evening to when it crashed at midnight, The driver caching all this information is consuming all the systems memory. I was running three Bluetooth smart sensors sending notifications every 20-50ms of 20 bytes each for six hours. This shouldn't consume all 4GiB of RAM on my machine, but it seems it does. Previously t has just crashed my program after this many hours, but this morning I found my machine had rebooted at the expected time.

    Peter

    Ps. I also don't know how to remove my upvote for your reply which was a mistake.

    Tuesday, November 3, 2015 9:54 AM
  • Finally I found it, It is a memory leak:

    https://support.microsoft.com/en-us/kb/2934794

    • Marked as answer by Ivan Chepiga Friday, February 12, 2016 7:40 PM
    • Edited by Ivan Chepiga Friday, February 12, 2016 7:41 PM
    Friday, February 12, 2016 7:40 PM