Skip to content

Commit 19fb38b

Browse files
jeanseb6windrjarry
authored andcommitted
data: update free method
Currently, if we use the free_func feature, we can't call the free method (similary to a parent method). If we do, we enter in an infinite loop. This patch allows to call free_internal from the free_func in order to avoid infinite loop.
1 parent c76f954 commit 19fb38b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

libyang/data.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def __init__(self, context: "libyang.Context", cdata):
216216
"""
217217
self.context = context
218218
self.cdata = cdata # C type: "struct lyd_node *"
219-
self.free_func = None # type: Callable[struct lyd_node *]
219+
self.free_func = None # type: Callable[DNode]
220220

221221
def meta(self):
222222
ret = {}
@@ -790,14 +790,18 @@ def merge_data_dict(
790790
rpcreply=rpcreply,
791791
)
792792

793+
def free_internal(self, with_siblings: bool = True) -> None:
794+
if with_siblings:
795+
lib.lyd_free_all(self.cdata)
796+
else:
797+
lib.lyd_free_tree(self.cdata)
798+
793799
def free(self, with_siblings: bool = True) -> None:
794800
try:
795801
if self.free_func:
796-
self.free_func(self.cdata) # pylint: disable=not-callable
797-
elif with_siblings:
798-
lib.lyd_free_all(self.cdata)
802+
self.free_func(self) # pylint: disable=not-callable
799803
else:
800-
lib.lyd_free_tree(self.cdata)
804+
self.free_internal(with_siblings)
801805
finally:
802806
self.cdata = None
803807

0 commit comments

Comments
 (0)