Skip to content

context/data: memleak due to API (mis)use #131

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions libyang/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ def __init__(
raise self.error("cannot create context")
self.external_module_loader = ContextExternalModuleLoader(self.cdata)


def __del__(self):
self.destroy()

def compile_schema(self):
ret = lib.ly_ctx_compile(self.cdata)
if ret != lib.LY_SUCCESS:
Expand All @@ -269,7 +273,11 @@ def get_yanglib_data(self, content_id_format=""):
ret = lib.ly_ctx_get_yanglib_data(self.cdata, dnode, str2c(content_id_format))
if ret != lib.LY_SUCCESS:
raise self.error("cannot get yanglib data")
return DNode.new(self, dnode[0])
# The refcnt_parent parameter here is Context rather than all other cases
# where it is DNode. Its not entirely clear how else to do it, pretty
# sure this returns internal memory that can't be passed to
# lyd_free_all() or lyd_free_tree() though docs on this aren't great.
return DNode.new(self, dnode[0], self)

def destroy(self):
if self.cdata is not None:
Expand Down Expand Up @@ -466,7 +474,7 @@ def create_data_path(
if not dnode:
raise self.error("cannot find created path")

return DNode.new(self, dnode)
return DNode.new(self, dnode, parent)

def parse_op(
self,
Expand Down Expand Up @@ -495,7 +503,7 @@ def parse_op(
if ret != lib.LY_SUCCESS:
raise self.error("failed to parse input data")

return DNode.new(self, op[0])
return DNode.new(self, op[0], parent)

def parse_op_mem(
self,
Expand Down Expand Up @@ -578,7 +586,7 @@ def parse_data(
dnode = dnode[0]
if dnode == ffi.NULL:
return None
return DNode.new(self, dnode)
return DNode.new(self, dnode, parent)

def parse_data_mem(
self,
Expand Down
Loading
Loading