Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ibnetdisc: Fix leak in add_to_portlid_hash #1409

Merged
merged 1 commit into from Dec 17, 2023

Conversation

aikuchin
Copy link
Contributor

@aikuchin aikuchin commented Nov 23, 2023

When the duplicate port is added to the map cl_qmap_insert() returns pointer to existing value and the new entry is left unused that results in leak:

==1606814== 2,624 bytes in 41 blocks are definitely lost in loss record 1 of 1
==1606814== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==1606814== by 0x5174B59: add_to_portlid_hash (ibnetdisc.c:704)
==1606814== by 0x517638E: recv_port_info (ibnetdisc.c:379)
==1606814== by 0x51789B0: process_one_recv (query_smp.c:200)
==1606814== by 0x5178EF7: process_mads (query_smp.c:276)
==1606814== by 0x51755E7: ibnd_discover_fabric (ibnetdisc.c:817)
==1606814== by 0x109229: main (in /vagrant/go/gpu/ib-ict-manager/a.out)

The solution is to free new item if it was not added to the map.

Fixes: 1616816 ("ibdiags: Use cl_qmap instead of glib hashtable")

UPD: Fixed format of "Fixes" tag, the only problem reported by CI is a long line in valgrind output, but I think it is better to keep it that way than wrap the line.

When the duplicate port is added to the map cl_qmap_insert() returns pointer
to existing value and the new entry is left unused that results in leak:

==1606814== 2,624 bytes in 41 blocks are definitely lost in loss record 1 of 1
==1606814==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==1606814==    by 0x5174B59: add_to_portlid_hash (ibnetdisc.c:704)
==1606814==    by 0x517638E: recv_port_info (ibnetdisc.c:379)
==1606814==    by 0x51789B0: process_one_recv (query_smp.c:200)
==1606814==    by 0x5178EF7: process_mads (query_smp.c:276)
==1606814==    by 0x51755E7: ibnd_discover_fabric (ibnetdisc.c:817)
==1606814==    by 0x109229: main (in /vagrant/go/gpu/ib-ict-manager/a.out)

The solution is to free new item if it was not added to the map.

Fixes: 1616816 ("ibdiags: Use cl_qmap instead of glib hashtable")

Signed-off-by: Anton Kuchin <[email protected]>
@aikuchin aikuchin force-pushed the fix_leak_in_add_to_portlid_hash branch 2 times, most recently from 9ce8974 to 5814d78 Compare November 28, 2023 11:52
@rleon rleon merged commit 482b7fb into linux-rdma:master Dec 17, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants