libyaml icon indicating copy to clipboard operation
libyaml copied to clipboard

Memory Leak in api.c

Open zhaohuanqdcn opened this issue 10 months ago • 3 comments

Hey all,

I would like to report a memory leak detected with ASAN in api.c.

The leak can be trigged an input with invalid trailing UTF-8 octet, and one such input is attached.

input.txt

To reproduce, simply run ./tests/run-parser-test-suite input.txt after building with ASAN (CFLAGS="-fsanitize=address -g -O1")

The ASAN report will look like:

Parse error: invalid trailing UTF-8 octet

=================================================================
==3391==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 50176 byte(s) in 5 object(s) allocated from:
    #0 0x7ffff7682887 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x55555555bc75 in yaml_malloc /libyaml-asan/src/api.c:33

SUMMARY: AddressSanitizer: 50176 byte(s) leaked in 5 allocation(s).

zhaohuanqdcn avatar May 07 '25 15:05 zhaohuanqdcn

Thanks! The leak is actually caused by a missing yaml_parser_delete in tests/run-parser-test-suite.c. That should be easy to fix, but is not a bug in libyaml itself.

But thanks to the report I also found a missing yaml_parser_delete in YAML-LibYAML: https://github.com/ingydotnet/yaml-libyaml-pm/pull/123

perlpunk avatar May 10 '25 15:05 perlpunk

why did you close it?

perlpunk avatar May 15 '25 08:05 perlpunk

why did you close it?

Sorry, I thought it has been fixed

zhaohuanqdcn avatar May 17 '25 12:05 zhaohuanqdcn