Skip to content

Commit

Permalink
libyang3-py3: patch for memory leak
Browse files Browse the repository at this point in the history
Sent upstream here:
CESNET/libyang-python#129
  • Loading branch information
bradh352 committed Feb 16, 2025
1 parent 9292d0f commit 939da17
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/libyang3-py3.patch/0003-parse_module-memleak.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
From 6550259f36da08b9b4bc7e9c941b2e13e10661a1 Mon Sep 17 00:00:00 2001
From: Brad House <[email protected]>
Date: Wed, 5 Feb 2025 19:38:43 -0500
Subject: [PATCH] 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 (@bradh352)
---
libyang/context.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libyang/context.py b/libyang/context.py
index 1b1d4cd..8be232c 100644
--- a/libyang/context.py
+++ b/libyang/context.py
@@ -325,7 +325,9 @@ def parse_module(

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

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

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

1 change: 1 addition & 0 deletions src/libyang3-py3.patch/series
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
0001-debian.patch
0002-pr134-json-string-datatypes.patch
0003-parse_module-memleak.patch

0 comments on commit 939da17

Please sign in to comment.