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

Possible memory leak with ly_ctx_new / ly_ctx_destory #1569

Closed
rabhat31 opened this issue May 14, 2021 · 6 comments
Closed

Possible memory leak with ly_ctx_new / ly_ctx_destory #1569

rabhat31 opened this issue May 14, 2021 · 6 comments

Comments

@rabhat31
Copy link

rabhat31 commented May 14, 2021

Hi,
We're using libyang v 1.0.225 and libnetconf2 v 1.1.26 in our codebase and run into a possible memory leak with ly_ctx_new().
Here is the loss record:
==2249== 17,035 bytes in 66 blocks are still reachable in loss record 2,274 of 2,457
==2249== at 0x4CA3E26: malloc (vg_replace_malloc.c:299)
==2249== by 0x79321EB: parse_text (xml.c:738)
==2249== by 0x7933AB9: lyxml_parse_elem (xml.c:1098)
==2249== by 0x79339F0: lyxml_parse_elem (xml.c:1082)
==2249== by 0x79339F0: lyxml_parse_elem (xml.c:1082)
==2249== by 0x79339F0: lyxml_parse_elem (xml.c:1082)
==2249== by 0x7934095: lyxml_parse_mem (xml.c:1231)
==2249== by 0x796131A: yin_read_module (parser_yin.c:7468)
==2249== by 0x799D8F9: lys_parse_mem_ (tree_schema.c:1080)
==2249== by 0x799DA04: lys_parse_mem (tree_schema.c:1112)
==2249== by 0x790CD39: ly_ctx_new (context.c:142)

I know for a fact that we're calling the destructor (within which we destroy the context) before the process terminates. The destructor is something like this:
...
nc_client_destroy();
ly_ctx_destroy(_yang_context, NULL);
...

The funny thing about this is the behavior of ly_ctx_destroy. I put in some print statements to check that the functions are being called correctly.
print0
nc_client_destroy();
print1
ly_ctx_destroy(_yang_context, NULL);
print2

I see print0 and print1 but print2 does not show up. I even switched the order of nc_client_destroy and ly_ctx_destroy but nothing after ly_ctx_destroy gets printed. I'm not really sure what could be causing this behavior. Please let me know if you have any suggestions.

Thanks

@michalvasko
Copy link
Member

What exactly is _yang_context? Are you using your own context when connecting? Or you got this context from a session by calling nc_session_get_ctx()?

@rabhat31
Copy link
Author

We create our own context. _yang_context is allocated memory during the initialization stage of our program like so:
_yang_context = ly_ctx_new(PACKAGED_SCHEMA_DIR,
LY_CTX_NOYANGLIBRARY | LY_CTX_ALLIMPLEMENTED | LY_CTX_DISABLE_SEARCHDIR_CWD);

@rabhat31
Copy link
Author

Could this be related to #15 ?

@michalvasko
Copy link
Member

Okay, so then I do not understand how is using libnetconf2 relevant. As long as you are creating your own context and not passing it to any libnetconf2 API, it must be completely independent. As for your print functions, it would seem that your process is crashing, which would explain the "possible" leak as well. Have you checked that?

@rabhat31
Copy link
Author

This issue is not related to libyang.

@sharanjeetsinghmago
Copy link

@rabhat31 What was the issue and how did you fix this? I am facing something very similar and think I might be missing something in my implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants