Oliviers-OSS / libmpsse

Automatically exported from code.google.com/p/libmpsse
0 stars 0 forks source link

Possible memory leak in Open method #31

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I noticed that the memory usage started to rise exponentially when i disconnect 
the device from the host. The software tries to reconnect to the device by 
calling the Open method.

To reproduce the issue i ran the following code:

#include <mpsse.h>
#include <mcheck.h>

int main()
{
  mtrace();

  struct mpsse_context *Dev = Open(0x0403, 0x6014, I2C, ONE_HUNDRED_KHZ, MSB, IFACE_A, NULL, NULL);
  Stop(Dev);
  Close(Dev);
  Dev = NULL;

  muntrace();
}

The trace log:

Memory not freed:
-----------------
           Address     Size     Caller
0x0000000000137da8    0x128  at ./lib/libusb/libusb/core.c:1594
0x0000000000137ed8     0x10  at ./lib/libusb/libusb/io.c:2323
0x0000000000137ef0     0x10  at ./lib/libusb/libusb/io.c:2323
0x0000000000137f08     0x18  at ./lib/libusb-compat/libusb/core.c:523
0x0000000000137f28        0  at ./lib/libusb-compat/libusb/core.c:420
0x0000000000137f38      0x5  at ./lib/libusb/libusb/os/linux_usbfs.c:868
0x0000000000137f48      0x4  at ./lib/libusb/libusb/os/linux_usbfs.c:868
0x0000000000137f58   0x1018  at ./lib/libusb-compat/libusb/core.c:217
0x0000000000138f98   0x1034  at ./lib/libusb-compat/libusb/core.c:330
0x0000000000139fd0   0x1034  at ./lib/libusb-compat/libusb/core.c:330
0x000000000013b008   0x1034  at ./lib/libusb-compat/libusb/core.c:330
0x000000000013c040   0x1034  at ./lib/libusb-compat/libusb/core.c:330
0x000000000013d078   0x1034  at ./lib/libusb-compat/libusb/core.c:330
0x000000000013e0b0   0x1034  at ./lib/libusb-compat/libusb/core.c:330
0x000000000013f0e8     0x18  at ./lib/libusb-compat/libusb/core.c:523
0x000000000013f108     0x28  at ./lib/libusb-compat/libusb/core.c:420
0x000000000013f138     0x18  at ./lib/libusb-compat/libusb/core.c:523
0x000000000013f158      0x8  at ./lib/libusb-compat/libusb/core.c:479
0x000000000013f198      0x8  at ./lib/libusb-compat/libusb/core.c:479
0x000000000013f1a8     0x18  at ./lib/libusb-compat/libusb/core.c:454
0x000000000013f1c8      0x9  at ./lib/libusb-compat/libusb/core.c:435
0x000000000013f200     0x18  at ./lib/libusb-compat/libusb/core.c:523
0x000000000013f220     0x18  at ./lib/libusb-compat/libusb/core.c:454
0x000000000013f240     0x28  at ./lib/libusb-compat/libusb/core.c:420
0x000000000013f270     0x18  at ./lib/libusb-compat/libusb/core.c:454
0x000000000013f290     0x18  at ./lib/libusb-compat/libusb/core.c:523
0x000000000013f2c8      0x8  at ./lib/libusb-compat/libusb/core.c:479
0x000000000013f2d8     0x14  at ./lib/libusb-compat/libusb/core.c:420
0x000000000013f2f0     0x10  at ./lib/libusb-compat/libusb/core.c:479
0x000000000013f308     0x18  at ./lib/libusb-compat/libusb/core.c:454
0x000000000013f328     0x14  at ./lib/libusb-compat/libusb/core.c:420
0x000000000013f348     0x18  at ./lib/libusb-compat/libusb/core.c:523
0x000000000013f368     0x18  at ./lib/libusb-compat/libusb/core.c:454
0x000000000013f388     0x14  at ./lib/libusb-compat/libusb/core.c:420
0x000000000013f3d8     0x17  at ./lib/libusb-compat/libusb/core.c:435
0x000000000013f3f8     0x30  at ./lib/libusb-compat/libusb/core.c:454
0x000000000013f430     0x28  at ./lib/libusb-compat/libusb/core.c:420
0x000000000013f490      0x8  at ./lib/libusb-compat/libusb/core.c:479
0x000000000013f4a0     0x18  at ./lib/libusb-compat/libusb/core.c:454
0x000000000013f4e0      0x8  at ./lib/libusb-compat/libusb/core.c:479
0x000000000013f4f0     0x14  at ./lib/libusb-compat/libusb/core.c:420
0x0000000000140f98     0x40  at ./lib/libusb/libusb/core.c:533
0x0000000000140fe0     0x40  at ./lib/libusb/libusb/core.c:533
0x0000000000141028     0x40  at ./lib/libusb/libusb/core.c:533
0x0000000000141070      0x6  at ./lib/libusb/libusb/os/linux_usbfs.c:868
0x0000000000141080     0x40  at ./lib/libusb/libusb/core.c:533
0x00000000001410c8      0x6  at ./lib/libusb/libusb/os/linux_usbfs.c:868
0x00000000001410d8     0x40  at ./lib/libusb/libusb/core.c:533
0x0000000000141120      0x8  at ./lib/libusb/libusb/os/linux_usbfs.c:868
0x0000000000141130     0x40  at ./lib/libusb/libusb/core.c:533
0x0000000000141178      0x8  at ./lib/libusb/libusb/os/linux_usbfs.c:868

What am i forgetting to do? Is this an upstream bug?

Original issue reported on code.google.com by johan.gi...@gmail.com on 6 Sep 2013 at 12:39

GoogleCodeExporter commented 9 years ago
i'm using version 1.2-1 but version 1.3 has the same problem.

Original comment by johan.gi...@gmail.com on 6 Sep 2013 at 12:44

GoogleCodeExporter commented 9 years ago
Ok, found the bug.

On line 130 ftdi_init is executed, obviously only when connection succeeds 
mpsse->open is set to '1' on line 173 or 191. In the close function a check is 
done if mpsse is open, before ftdi_deinit is executed. Result: memory leak.

Have a nice weekend!

Original comment by johan.gi...@gmail.com on 6 Sep 2013 at 2:23

GoogleCodeExporter commented 9 years ago
Thanks, just checked in a fix to the trunk that should address this bug.

Original comment by heffne...@gmail.com on 16 Sep 2013 at 6:01