Skip to content

Commit 6e42fb3

Browse files
data: fix DNode double free
Calling free twice on a dnode is failing with libyang-python, when it is supported with libyang. That is because cdata is set to None in the free function. Set it to ffi.NULL so that libyang can see the NULL pointer. Fixes: #84 Signed-off-by: Stefan Gula <steweg@gmail.com> Signed-off-by: Samuel Gauthier <samuel.gauthier@6wind.com>
1 parent c6caf46 commit 6e42fb3

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

libyang/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ def free(self, with_siblings: bool = True) -> None:
881881
else:
882882
self.free_internal(with_siblings)
883883
finally:
884-
self.cdata = None
884+
self.cdata = ffi.NULL
885885

886886
def __repr__(self):
887887
cls = self.__class__

tests/test_data.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,3 +876,8 @@ def test_add_defaults(self):
876876
node = dnode.find_path("/yolo-system:conf/speed")
877877
self.assertIsInstance(node, DLeaf)
878878
self.assertEqual(node.value(), 4321)
879+
880+
def test_dnode_double_free(self):
881+
dnode = self.ctx.parse_data_mem(self.JSON_CONFIG, "json", validate_present=True)
882+
dnode.free()
883+
dnode.free()

0 commit comments

Comments
 (0)