libyang icon indicating copy to clipboard operation
libyang copied to clipboard

maybe memory leak when using realloc

Open lyzliyuzhi91 opened this issue 2 years ago • 1 comments

https://github.com/CESNET/libyang/blob/7e5ea21030fe6632b6faad30c0de8d9669503773/src/schema_compile_node.c#L1643C20-L1643C20

Hi, I use valgrind to run my program's testcase, and it report such :

==3455252== 40 bytes in 1 blocks are possibly lost in loss record 945 of 2,427
==3455252== at 0x4C2C8AB: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==3455252== by 0x50BBB09: lys_compile_type_union (schema_compile_node.c:1643)
==3455252== by 0x50BE01D: lys_compile_type_ (schema_compile_node.c:2058)
==3455252== by 0x50BF495: lys_compile_type (schema_compile_node.c:2279)
==3455252== by 0x50C1DCA: lys_compile_node_type (schema_compile_node.c:2924)
==3455252== by 0x50C235C: lys_compile_node_leaf (schema_compile_node.c:2987)
==3455252== by 0x50C0817: lys_compile_node_ (schema_compile_node.c:2705)
==3455252== by 0x50C6C2C: lys_compile_node (schema_compile_node.c:4263)
==3455252== by 0x50C196A: lys_compile_node_container (schema_compile_node.c:2881)
==3455252== by 0x50C0817: lys_compile_node_ (schema_compile_node.c:2705)
==3455252== by 0x50C6C2C: lys_compile_node (schema_compile_node.c:4263)
==3455252== by 0x50C4C53: lys_compile_node_case (schema_compile_node.c:3731)

But I cannot find out why it will cause memory-leak actually. version: 128

lyzliyuzhi91 avatar Nov 23 '23 09:11 lyzliyuzhi91

Yes, the type structures are being shared and it confuses valgrind. Once the context is destroyed, no data are leaked.

michalvasko avatar Nov 23 '23 09:11 michalvasko