-
Notifications
You must be signed in to change notification settings - Fork 296
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
Memory leak detected in valgrind when running libyang #2334
Comments
Please rerun the |
Thankss for the reply. I tried updating to the latest version of libyang 2.1 (2.1.148) to see if that changed any behaviour. The following stack traces are for that version. I have run the added the command and it seems to happen if we add the WITH_SIBLINGS flag when printing ==29002== at 0x483AD7B: realloc (vg_replace_malloc.c:834) ==32264== LEAK SUMMARY: If I don't use the WITH_SIBLINGS flag the memory leak is not nearly as bad ==30633== LEAK SUMMARY: |
As an added bit of information I have possibly found the leak. The allocation is happening here out->method.mem.buf = ly_realloc(*out->method.mem.buf, new_mem_size);
if (!*out->method.mem.buf)
{
out->method.mem.len = 0;
out->method.mem.size = 0;
LOGMEM(NULL);
return LY_EMEM;
} so memory is being allocated to out->method.mem.buf lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format, uint32_t options)
{
LY_ERR ret;
struct ly_out *out;
LY_CHECK_ARG_RET(NULL, strp, LY_EINVAL);
/* init */
*strp = NULL;
LY_CHECK_RET(ly_out_new_memory(strp, 0, &out));
ret = lyd_print_(out, root, format, options);
ly_out_free(out, NULL, 0);
return ret;
} lyd_print_mem calls ly_out_free with destroy of 0 so the buffer will never be cleared I have created a pull request #2336 |
Changing the 0 to a 1 and I get =85529== LEAK SUMMARY: Changing it back to a 0 and I get ==88651== LEAK SUMMARY: |
There is no leak, you must free the output string yourself. It cannot be freed right after printing, you would then get a freed string in your application. |
Sorry my mistake. Thank you for the reply. It seems that the actual culprit would be the yang3 package making use of the libyang library.
It does not seem to free the cstr |
Version: Libyang 2.1.80
Hi There,
We have an application and it has been found recently that a process in that application has been increasing in memory. Through some binary searching I was able to narrow it down to a change that was made involving libyang.
We have a typescript project that makes use of napi-rs to call rust code that natively runs libyang
I managed to run valgrind on our application running libyang and a definite memory leak was detected
==23236== LEAK SUMMARY:
==23236== definitely lost: 2,048 bytes in 1 blocks
==23236== indirectly lost: 0 bytes in 0 blocks
==23236== possibly lost: 857,350 bytes in 7,307 blocks
==23236== still reachable: 384 bytes in 2 blocks
==23236== of which reachable via heuristic:
==23236== newarray : 150,032 bytes in 1,044 blocks
==23236== suppressed: 0 bytes in 0 blocks
==23236== Reachable blocks (those to which a pointer was found) are not shown.
==23236== To see them, rerun with: --leak-check=full --show-leak-kinds=all
The leak seems to be coming from here
==23236== 2,048 bytes in 1 blocks are definitely lost in loss record 1,061 of 1,125
==23236== at 0x483AD7B: realloc (vg_replace_malloc.c:834)
==23236== by 0x485F58C: ly_realloc (in /usr/lib/x86_64-linux-gnu/libyang.so.2)
==23236== by 0x48907C7: ly_write_ (in /usr/lib/x86_64-linux-gnu/libyang.so.2)
==23236== by 0x4892B7F: json_print_string.part.0 (in /usr/lib/x86_64-linux-gnu/libyang.so.2)
==23236== by 0x4892C68: json_print_value (in /usr/lib/x86_64-linux-gnu/libyang.so.2)
==23236== by 0x4893C3F: json_print_node.part.0 (in /usr/lib/x86_64-linux-gnu/libyang.so.2)
==23236== by 0x48946FA: json_print_inner (in /usr/lib/x86_64-linux-gnu/libyang.so.2)
==23236== by 0x4894212: json_print_node.part.0 (in /usr/lib/x86_64-linux-gnu/libyang.so.2)
==23236== by 0x48946FA: json_print_inner (in /usr/lib/x86_64-linux-gnu/libyang.so.2)
==23236== by 0x4894212: json_print_node.part.0 (in /usr/lib/x86_64-linux-gnu/libyang.so.2)
==23236== by 0x48946FA: json_print_inner (in /usr/lib/x86_64-linux-gnu/libyang.so.2)
==23236== by 0x4893C72: json_print_node.part.0 (in /usr/lib/x86_64-linux-gnu/libyang.so.2)
If I run the application multiple times then the memory lost will increase by number of runs * 2Kb
Kind regards
The text was updated successfully, but these errors were encountered: