libnetconf2 icon indicating copy to clipboard operation
libnetconf2 copied to clipboard

Memory leak reported by valgrind in nc_session_free() and nc_read_msg_poll_io()

Open ajithb opened this issue 3 years ago • 7 comments
trafficstars

Hello, I am using libnetconf2 version 1.1.26 and see that valgrind (memcheck tool) reports quite a lot of memory leaks as indirectly lost. Here is a stack trace of one of the reports. Could you please check and let me know if this is fixed in any version of netconf2. Is this indeed an actual memory leak in the code or is it a false positive reported by memcheck tool. I would very much appreciate your inputs on this. libnetconf2 version 1.1.26 libyang version 1.0.240

memory leak from nc_session_free() call stack

==2527== 10,656 bytes in 148 blocks are indirectly lost in loss record 55 of 59
==2527==    at 0x48ABA35: calloc (vg_replace_malloc.c:760)
==2527==    by 0x682EB1C: lyxml_parse_elem (xml.c:1010)
==2527==    by 0x682F281: lyxml_parse_elem (xml.c:1150)
==2527==    by 0x682F281: lyxml_parse_elem (xml.c:1150)
==2527==    by 0x682F281: lyxml_parse_elem (xml.c:1150)
==2527==    by 0x682F281: lyxml_parse_elem (xml.c:1150)
==2527==    by 0x682F281: lyxml_parse_elem (xml.c:1150)
==2527==    by 0x682F684: lyxml_parse_mem (xml.c:1304)
==2527==    by 0x67B0B99: nc_read_msg_io (io.c:458)
==2527==    by 0x67B11AE: nc_read_msg_poll_io (io.c:665)
==2527==    by 0x67B5950: nc_session_free (session.c:659)
==2527==    by 0x6539688: NetconfClient::close_session() (netconfclient.cc:42)

And here is the reported leak from nc_read_msg_poll_io() call stack

==2527== 93,375 (72 direct, 93,303 indirect) bytes in 1 blocks are definitely lost in loss record 59 of 59
==2527==    at 0x48ABA35: calloc (vg_replace_malloc.c:760)
==2527==    by 0x682EB1C: lyxml_parse_elem (xml.c:1010)
==2527==    by 0x682F281: lyxml_parse_elem (xml.c:1150)
==2527==    by 0x682F281: lyxml_parse_elem (xml.c:1150)
==2527==    by 0x682F281: lyxml_parse_elem (xml.c:1150)
==2527==    by 0x682F281: lyxml_parse_elem (xml.c:1150)
==2527==    by 0x682F281: lyxml_parse_elem (xml.c:1150)
==2527==    by 0x682F281: lyxml_parse_elem (xml.c:1150)
==2527==    by 0x682F281: lyxml_parse_elem (xml.c:1150)
==2527==    by 0x682F684: lyxml_parse_mem (xml.c:1304)
==2527==    by 0x67B0B99: nc_read_msg_io (io.c:458)
==2527==    by 0x67B11AE: nc_read_msg_poll_io (io.c:665)

ajithb avatar Apr 13 '22 22:04 ajithb

Hi @michalvasko , I see in the release notes that version 1.x is deprecated and 2.x should be used. Because of time crunch on the project and the task it involves (upgrading to libyang 2.x and netconf2 2.x together), this could take up a lot of time for us. If the solution to this memory leaks involves upgrading the libraries, may I ask if upgrading to libnetconf2 v1.1.46 be an option and likely fix this error for me. I am trying to get a quicker fix for now and eventually upgrade to libyang v2.x and libnetconf2 2.x.

ajithb avatar Apr 13 '22 23:04 ajithb

Yes, I think this may be a memory leak I have fixed a long time ago in v2.

michalvasko avatar Apr 14 '22 06:04 michalvasko

Thanks Michal for confirming it actually is a bug. Just to confirm, is the fix not available in any v1.x version ? If so, which version of v2 has this fix.

ajithb avatar Apr 14 '22 06:04 ajithb

Looking at the old code, it was a different bug I had in mind. However, there are no XML structures in version 2 so the bug is definitely not present. You can try to update the v1 version to the latest 1.1.48 and check whether it is fixed.

michalvasko avatar Apr 14 '22 06:04 michalvasko

Will do. Thanks a lot for the quick comments..

ajithb avatar Apr 14 '22 07:04 ajithb

Hi @michalvasko I do not see a version 1.1.48 in release archives. Did you mean 1.1.46 ?

ajithb avatar Apr 14 '22 18:04 ajithb

No, the latest version was not released (and maybe never will be), it is only in the libyang1 branch.

michalvasko avatar Apr 19 '22 08:04 michalvasko

hi, @ajithb Is this problem solved in version 48?

sourcema avatar Apr 04 '23 09:04 sourcema