USB device stack
Dependents:
mbed-mX-USB-TEST1
USBMSD_SD_HID_HelloWorld
HidTest
MIDI_usb_bridge
... more
7 comments:
Both for mbed people and other people with the issue: Version with hopefully all memory leaks closed: http://mbed.org/users/Sissors/code/USBDevice/.
I found that not only does connecting/disconnecting result in memory leaks, but in a single call to 'connect', one buffer was allocated 4 times!
Btw are those issues actually monitored?
Whoops, guess I converted it to folder and back to library.
With the locations I listed here it should be doable to figure out what is changed ;). Btw I think the fix I used in USBHAL_KL25.cpp isn't the most elegant possibility, but it worked for me.
That's exactly what I wanted to ask you :) I wonder if "disconnect" is the right place to free the buffers. Of course it's better than nothing, but I don't know if it's ideal. How did you test your changes?
There is an example program included in the issue report, the issue links that at the bottom (granted, it is easy to overlook it): http://mbed.org/users/Sissors/code/USBMSB_KL25Z_memoryleaks/. There the USBDevice library has some printfs, it should work if you just put in my version of the USBDevice library, if you don't do that it should depending on when it runs out of memory display its memory is full or simply crash. I tested it myself on the KL25Z, with less RAM than LPC1768 you don't have to wait as long, also because it has more memory leaks, in a few connects/disconnects it should run out of memory.
That example program also has printfs everytime a buffer is allocated, which is quite often.
I think for the USBMSD code the logical place to de-allocate the buffer is in disconnect, since it allocates it when connecting it makes sense to de-allocate it in disconnect, and then force disconnect to be called in the destructor. Although there is also the question what happens when disconnect or connect is called multiple times in a row. Not something taken care of now by my version of the library. The USBHAL part has a two-fold problem: it allocates memory on connect and doesn't de-allocate it on disconnect/destruction, but also on a single connect it allocates the same pointer multiple times.
I ran into it while making http://mbed.org/users/Sissors/code/USBFileSystem/, combination of FATFileSystem and USBMSD device. When the program is writing to the filesystem it should disconnect the USBMSD device and reconnect later. But it always ran out of memory in a few times, so I started investigating.
I've pushed your changes, along with a few minor changes of my own. Thanks!
Both for mbed people and other people with the issue: Version with hopefully all memory leaks closed: http://mbed.org/users/Sissors/code/USBDevice/.
I found that not only does connecting/disconnecting result in memory leaks, but in a single call to 'connect', one buffer was allocated 4 times!