libyaml icon indicating copy to clipboard operation
libyaml copied to clipboard

Free version_directive if not stored for later use

Open hhorak opened this issue 5 years ago • 4 comments

This was an error returned from Coverity static analysis tool:

Error: RESOURCE_LEAK (CWE-772):

yaml-0.1.7/src/parser.c:1273: alloc_fn: Storage is returned from allocation function "yaml_malloc". yaml-0.1.7/src/api.c:33:5: alloc_fn: Storage is returned from allocation function "malloc". yaml-0.1.7/src/api.c:33:5: return_alloc_fn: Directly returning storage allocated by "malloc". yaml-0.1.7/src/parser.c:1273: var_assign: Assigning: "version_directive" = storage returned from "yaml_malloc(8UL)". yaml-0.1.7/src/parser.c:1323: leaked_storage: Variable "version_directive" going out of scope leaks the storage it points to. 1321| } 1322| 1323|-> return 1; 1324| 1325| error:

Downstream report: https://bugzilla.redhat.com/show_bug.cgi?id=1602610

Credits to @kdudka, who originally suggested this patch in the bz above.

hhorak avatar Aug 08 '19 12:08 hhorak

Thanks, but there is a missing } for the previous if

perlpunk avatar Mar 28 '20 17:03 perlpunk

Yes, the current version of the code is good as it is. The resource leak had been fixed by commit f0330018390eb73ae2dead53467a59ad76d67d5e and commit df5c05e12080c6f710da54b6e3348288f3506d46, which were included in libyaml-0.2.2. @hhorak was reviewing libyaml-0.1.7, which contained the resource leak in question.

kdudka avatar Aug 02 '22 09:08 kdudka

Okay, so the bug motivating this PR was fixed already more than a year in advance of this PR being opened. I believe this PR should be closed.

dtolnay avatar Aug 02 '22 11:08 dtolnay

@dtolnay That is exactly my understanding of it!

kdudka avatar Aug 02 '22 13:08 kdudka