Repository navigation
Commit 768825f
committed
data: fix memory leak when printing data to memory
When print() writes to memory, libyang allocates the output buffer.
ly_out_free() is called without the destroy flag, so the buffer stays
allocated, and print() copies it into a python string but never frees
it. Each call leaks the printed data.
Free the buffer after the copy. With a 10 kB leaf printed 10000 times,
the RSS growth is:
before: 100156 kB
after: 0 kB
Note that print_mem() and Module.print() already free their buffer.
Fixes: 806be4c ("Port to libyang 2")
Signed-off-by: Samuel Gauthier <samuel.gauthier@6wind.com>1 parent 37e1091 commit 768825f
1 file changed
Lines changed: 6 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
723 | 723 | | |
724 | 724 | | |
725 | 725 | | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
730 | 732 | | |
731 | 733 | | |
732 | 734 | | |
| |||
0 commit comments