Skip to content

Commit 8534053

Browse files
bradh352rjarry
authored andcommitted
context: correct memory leak of struct ly_in * objects
`data_load()` returns a reference to `struct ly_in *` which must be free'd by `lys_in_free()`. This is done in one of three locations. This corrects this oversight. This was found during unit tests of SONiC during porting to libyang3 from libyang 1.0.73. Signed-off-by: Brad House <[email protected]>
1 parent aea34d1 commit 8534053

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

libyang/context.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,9 @@ def parse_module(
325325

326326
mod = ffi.new("struct lys_module **")
327327
fmt = schema_in_format(fmt)
328-
if lib.lys_parse(self.cdata, data[0], fmt, feat, mod) != lib.LY_SUCCESS:
328+
ret = lib.lys_parse(self.cdata, data[0], fmt, feat, mod)
329+
lib.ly_in_free(data[0], 0)
330+
if ret != lib.LY_SUCCESS:
329331
raise self.error("failed to parse module")
330332

331333
return Module(self, mod[0])
@@ -489,6 +491,7 @@ def parse_op(
489491
par[0] = parent.cdata
490492

491493
ret = lib.lyd_parse_op(self.cdata, par[0], data[0], fmt, dtype, tree, op)
494+
lib.ly_in_free(data[0], 0)
492495
if ret != lib.LY_SUCCESS:
493496
raise self.error("failed to parse input data")
494497

0 commit comments

Comments
 (0)