|
| 1 | +From 6550259f36da08b9b4bc7e9c941b2e13e10661a1 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Brad House <brad@brad-house.com> |
| 3 | +Date: Wed, 5 Feb 2025 19:38:43 -0500 |
| 4 | +Subject: [PATCH] correct memory leak of `struct ly_in *` objects |
| 5 | + |
| 6 | +`data_load()` returns a reference to `struct ly_in *` which |
| 7 | +must be free'd by `lys_in_free()`. This is done in one of three |
| 8 | +locations. This corrects this oversight. |
| 9 | + |
| 10 | +This was found during unit tests of SONiC during porting to |
| 11 | +libyang3 from libyang 1.0.73. |
| 12 | + |
| 13 | +Signed-off-by: Brad House (@bradh352) |
| 14 | +--- |
| 15 | + libyang/context.py | 5 ++++- |
| 16 | + 1 file changed, 4 insertions(+), 1 deletion(-) |
| 17 | + |
| 18 | +diff --git a/libyang/context.py b/libyang/context.py |
| 19 | +index 1b1d4cd..8be232c 100644 |
| 20 | +--- a/libyang/context.py |
| 21 | ++++ b/libyang/context.py |
| 22 | +@@ -325,7 +325,9 @@ def parse_module( |
| 23 | + |
| 24 | + mod = ffi.new("struct lys_module **") |
| 25 | + fmt = schema_in_format(fmt) |
| 26 | +- if lib.lys_parse(self.cdata, data[0], fmt, feat, mod) != lib.LY_SUCCESS: |
| 27 | ++ rv = lib.lys_parse(self.cdata, data[0], fmt, feat, mod) |
| 28 | ++ lib.ly_in_free(data[0], 0) |
| 29 | ++ if rv != lib.LY_SUCCESS: |
| 30 | + raise self.error("failed to parse module") |
| 31 | + |
| 32 | + return Module(self, mod[0]) |
| 33 | +@@ -489,6 +491,7 @@ def parse_op( |
| 34 | + par[0] = parent.cdata |
| 35 | + |
| 36 | + ret = lib.lyd_parse_op(self.cdata, par[0], data[0], fmt, dtype, tree, op) |
| 37 | ++ lib.ly_in_free(data[0], 0) |
| 38 | + if ret != lib.LY_SUCCESS: |
| 39 | + raise self.error("failed to parse input data") |
| 40 | + |
0 commit comments