Closed mweal-ed closed 2 years ago
Managed to get my BBB back, so was able to verify the memory leak is on the BBB too, so this is not a Pi issue.
debian@arm:~$ sudo usb-mitm -l
[sudo] password for debian:
Loading plugins from /usr/local/lib/USBProxy/
vendorId=ffffffff
productId=ffffffff
cleaning up /tmp
removing 1
Made directory /tmp/gadget-LVdjYu for gadget
Printing Config data
Strings: 2
DeviceProxy: DeviceProxy_LibUSB
HostProxy: HostProxy_GadgetFS
Vectors: 1
Plugins:
PacketFilter_StreamLog
Pointer: 1
PacketFilter_StreamLog::file: 0xb6d55540
Device: 12 01 00 02 00 00 00 40 b8 04 02 02 00 01 01 02 03 01
Manufacturer: EPSON
Product: TM-T88V
Serial: 4D5844469389310000
*Config(1): 09 02 20 00 01 01 00 e0 01
Interface(0):
*Alt(0): 09 04 00 00 02 ff ff 02 00
EP(01): 07 05 01 02 40 00 00
EP(82): 07 05 82 02 40 00 00
old bInterval: 00
calculated new bInterval: 80000000
old bInterval: 00
calculated new bInterval: 80000000
searching in [/tmp/gadget-LVdjYu]
Starting setup writer thread (2149) for EP00.
Starting setup reader thread (2148) for EP00.
[80 06 03 03 09 04 ff 00]
[80 06 03 03 09 04 26 00]:
26 03 34 00 44 00 35 00 38 00 34 00 34 00 34 00 36 00 39 00 33 00 38 00 39 00 33 00 31 00 30 00
30 00 30 00 30 00
[80 06 00 03 00 00 ff 00]
[80 06 00 03 00 00 04 00]: 04 03 09 04
[80 06 02 03 09 04 ff 00]
[80 06 02 03 09 04 10 00]: 10 03 54 00 4d 00 2d 00 54 00 38 00 38 00 56 00
[80 06 02 03 00 00 00 04]
[80 06 02 03 00 00 10 00]: 10 03 54 00 4d 00 2d 00 54 00 38 00 38 00 56 00
[00 09 01 00 00 00 00 00]
Opened EP01
Opened EP82
[c1 00 00 00 00 00 02 00]
[c1 00 00 00 00 00 02 00]: 26 30
Starting writer thread (2154) for EP82.
[41 06 00 30 00 00 00 00]
[c1 00 00 00 00 00 02 00]
Starting reader thread (2153) for EP82.
Starting writer thread (2152) for EP01.
[c1 00 00 00 00 00 02 00]: 26 30
Starting reader thread (2151) for EP01.
[80 06 00 03 00 00 00 04]
[80 06 00 03 00 00 04 00]: 04 03 09 04
[80 06 01 03 09 04 00 04]
[80 06 01 03 09 04 0c 00]: 0c 03 45 00 50 00 53 00 4f 00 4e 00
[80 06 02 03 09 04 00 04]
[80 06 02 03 09 04 10 00]: 10 03 54 00 4d 00 2d 00 54 00 38 00 38 00 56 00
[80 06 03 03 09 04 00 04]
[80 06 03 03 09 04 26 00]:
26 03 34 00 44 00 35 00 38 00 34 00 34 00 34 00 36 00 39 00 33 00 38 00 39 00 33 00 31 00 30 00
30 00 30 00 30 00
[c1 00 00 00 00 00 02 00]
[c1 00 00 00 00 00 02 00]: 26 30
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 02 00
[c1 00 00 00 00 00 02 00]
[c1 00 00 00 00 00 02 00]: 26 30
[41 02 02 00 00 00 00 00]
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 02 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 02 00
[41 11 00 00 00 00 00 00]
01[7]: 10 04 01 10 14 07 01
82[1]: 16
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 02 00
[41 11 00 00 00 00 00 00]
01[4]: 10 04 03 00
82[1]: 12
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 02 00
[c1 00 00 00 00 00 02 00]
[c1 00 00 00 00 00 02 00]: 26 30
[41 02 00 00 00 00 00 00]
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[41 11 00 00 00 00 00 00]
01[9]: 1b 28 73 04 00 31 41 a7 90
82[20]: 7b 20 41 35 37 34 41 34 46 35 34 34 37 34 32 34 46 34 38 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[41 11 00 00 00 00 00 00]
01[3]: 1d 49 71
82[3]: 5f 31 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[41 11 00 00 00 00 00 00]
01[3]: 1d 49 45
82[2]: 5f 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[41 11 00 00 00 00 00 00]
01[3]: 1d 49 60
82[4]: 3d 60 49 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[41 11 00 00 00 00 00 00]
01[3]: 1d 49 01
82[1]: 20
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[c1 00 00 00 00 00 02 00]
[c1 00 00 00 00 00 02 00]: 26 30
[41 02 00 00 00 00 00 00]
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[41 11 00 00 00 00 00 00]
01[3]: 1d 61 ff
82[4]: 14 00 00 0f
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
[c1 01 00 00 00 00 02 00]
[c1 01 00 00 00 00 02 00]: 00 00
debian@arm:~$
[ 490.761891] gadgetfs: configuration #1
[ 562.737185] usb-mitm invoked oom-killer: gfp_mask=0x200da, order=0, oom_score_adj=0
[ 562.745322] usb-mitm cpuset=/ mems_allowed=0
[ 562.749833] CPU: 0 PID: 2153 Comm: usb-mitm Not tainted 3.12.0-bone8 #1
[ 562.756841] [<c00136fc>] (unwind_backtrace+0x0/0xdc) from [<c0010a30>] (show_stack+0x10/0x14)
[ 562.765838] [<c0010a30>] (show_stack+0x10/0x14) from [<c05bdc88>] (dump_stack+0x70/0x8c)
[ 562.774367] [<c05bdc88>] (dump_stack+0x70/0x8c) from [<c05ba42c>] (dump_header.isra.8+0x78/0x17c)
[ 562.783736] [<c05ba42c>] (dump_header.isra.8+0x78/0x17c) from [<c00b5e00>] (oom_kill_process+0x6c/0x360)
[ 562.793723] [<c00b5e00>] (oom_kill_process+0x6c/0x360) from [<c00b6504>] (out_of_memory+0x26c/0x29c)
[ 562.803342] [<c00b6504>] (out_of_memory+0x26c/0x29c) from [<c00b9898>] (__alloc_pages_nodemask+0x648/0x7bc)
[ 562.813607] [<c00b9898>] (__alloc_pages_nodemask+0x648/0x7bc) from [<c00d0afc>] (handle_mm_fault+0x770/0x8e0)
[ 562.824062] [<c00d0afc>] (handle_mm_fault+0x770/0x8e0) from [<c00166fc>] (do_page_fault+0x114/0x370)
[ 562.833684] [<c00166fc>] (do_page_fault+0x114/0x370) from [<c000842c>] (do_DataAbort+0x34/0x98)
[ 562.842845] [<c000842c>] (do_DataAbort+0x34/0x98) from [<c00115b4>] (__dabt_usr+0x34/0x40)
[ 562.851542] Exception stack(0xddc33fb0 to 0xddc33ff8)
[ 562.856864] 3fa0: 00000209 00003f69 1d920098 00000000
[ 562.865473] 3fc0: b6d56258 00000209 b6d56694 1d91fe98 00004170 00000218 00000208 00000040
[ 562.874080] 3fe0: b6d56290 b43d7ca8 b6cc8f37 b6cc94ea 00000030 ffffffff
[ 562.881039] Mem-info:
[ 562.883438] Normal per-cpu:
[ 562.886383] CPU 0: hi: 186, btch: 31 usd: 58
[ 562.891438] active_anon:123245 inactive_anon:39 isolated_anon:0
[ 562.891438] active_file:40 inactive_file:25 isolated_file:0
[ 562.891438] unevictable:0 dirty:0 writeback:0 unstable:0
[ 562.891438] free:687 slab_reclaimable:420 slab_unreclaimable:1127
[ 562.891438] mapped:28 shmem:51 pagetables:365 bounce:0
[ 562.891438] free_cma:0
[ 562.923809] Normal free:2748kB min:2848kB low:3560kB high:4272kB active_anon:492980kB inactive_anon:156kB active_file:160kB inactive_file:100kB unevictable:0kB isolated(anon):0kB isolated(file):0kB present:523264kB managed:508188kB mlocked:0kB dirty:0kB writeback:0kB mapped:112kB shmem:204kB slab_reclaimable:1680kB slab_unreclaimable:4508kB kernel_stack:672kB pagetables:1460kB unstable:0kB bounce:0kB free_cma:0kB writeback_tmp:0kB pages_scanned:11076 all_unreclaimable? yes
[ 562.967814] lowmem_reserve[]: 0 0 0
[ 562.971511] Normal: 1*4kB (R) 1*8kB (R) 1*16kB (R) 1*32kB (R) 0*64kB 1*128kB (R) 0*256kB 1*512kB (R) 0*1024kB 1*2048kB (R) 0*4096kB 0*8192kB = 2748kB
[ 562.985725] 118 total pagecache pages
[ 562.989594] 0 pages in swap cache
[ 562.993088] Swap cache stats: add 0, delete 0, find 0/0
[ 562.998587] Free swap = 0kB
[ 563.001607] Total swap = 0kB
[ 563.022160] 131072 pages of RAM
[ 563.025469] 919 free pages
[ 563.028343] 4025 reserved pages
[ 563.031657] 1547 slab pages
[ 563.034605] 263228 pages shared
[ 563.037900] 0 pages swap cached
[ 563.041210] [ pid ] uid tgid total_vm rss nr_ptes swapents oom_score_adj name
[ 563.049489] [ 383] 0 383 603 123 4 0 -1000 udevd
[ 563.057828] [ 504] 0 504 601 121 3 0 -1000 udevd
[ 563.066165] [ 505] 0 505 601 121 3 0 -1000 udevd
[ 563.074501] [ 718] 0 718 328 18 3 0 0 logsave
[ 563.083018] [ 1312] 0 1312 328 18 3 0 0 logsave
[ 563.091536] [ 1654] 0 1654 1027 437 4 0 0 dhclient
[ 563.100143] [ 1839] 0 1839 7099 138 7 0 0 rsyslogd
[ 563.108760] [ 1893] 0 1893 839 48 4 0 0 cron
[ 563.117005] [ 1923] 101 1923 647 66 4 0 0 dbus-daemon
[ 563.125894] [ 1950] 102 1950 716 83 4 0 0 avahi-daemon
[ 563.134870] [ 1951] 102 1951 691 63 4 0 0 avahi-daemon
[ 563.143843] [ 2080] 0 2080 1298 114 4 0 -1000 sshd
[ 563.152086] [ 2104] 0 2104 836 42 5 0 0 getty
[ 563.160420] [ 2105] 0 2105 836 42 4 0 0 getty
[ 563.168755] [ 2106] 0 2106 836 42 4 0 0 getty
[ 563.177090] [ 2107] 0 2107 836 42 4 0 0 getty
[ 563.185427] [ 2108] 0 2108 836 42 4 0 0 getty
[ 563.193762] [ 2109] 0 2109 836 42 4 0 0 getty
[ 563.202097] [ 2110] 0 2110 416 41 4 0 0 getty
[ 563.210432] [ 2117] 0 2117 2074 168 6 0 0 sshd
[ 563.218676] [ 2119] 1000 2119 2107 172 5 0 0 sshd
[ 563.226918] [ 2120] 1000 2120 1032 94 5 0 0 bash
[ 563.235162] [ 2127] 0 2127 2074 168 6 0 0 sshd
[ 563.243404] [ 2129] 1000 2129 2107 172 5 0 0 sshd
[ 563.251647] [ 2130] 1000 2130 1033 94 4 0 0 bash
[ 563.259889] [ 2140] 1000 2140 747 31 4 0 0 free
[ 563.268163] [ 2143] 0 2143 1018 84 4 0 0 sudo
[ 563.276415] [ 2144] 0 2144 136591 121206 248 0 0 usb-mitm
[ 563.285022] Out of memory: Kill process 2144 (usb-mitm) score 925 or sacrifice child
[ 563.293176] Killed process 2144 (usb-mitm) total-vm:546364kB, anon-rss:484704kB, file-rss:120kB
[ 563.539599] gadgetfs: disconnected
Looks like this is a duplicate of issue #6 and issue #51.
I have tried running the code under valgrind on the BBB, but it does not work. I tried heapusage and all it tells me is I have a leak on the heap. I was unable to run memleax on either the pi or the BBB.
Looks like the problem is that DeviceProxy_LibUSB::receive_data allocates memory for all received packet data. Normally RelayReader::relay_read enqueues this buffer, and it is freed after the data is dequeued. However when a zero length packet is received, the buffer is never enqueued and thus is never dequeued and freed. The fix is changing the following in RelayReader::relay_read from
if (length)
_sendQueue->enqueue(std::make_shared<Packet>(endpoint, buf, length));
to
if (length)
_sendQueue->enqueue(std::make_shared<Packet>(endpoint, buf, length));
else
free(buf);
This hopefully fixes the memory leaks in issue #6, #51 and #79
Hi, @mweal-ed are you still experiencing this issue?
It has been a while since I worked on this project, but the fix above had solved the memory leak problem.
Thank you for the update. I'll close this issue.
I have USBProxy running on a Pi zero w and seem to be experiencing a memory leak.
When running "sudo usb-mitm -l" (with very little USB traffic) I get a linux oom error after a couple minutes. By running "free -m -s" in another window I see about 1MB per second of memory is being eaten. I have not been able to run this through valgrind as it does not support the Pi zero cpu, so debugging is going to be a bit more difficult.
1) I was wondering if someone could check this on a BBB, so I know if it is a Pi issue or USBProxy Issue.
2) Does Anyone suggestions as to what the problem may be.