Page MenuHomeFreeBSD

ctld: Consistently free temporary strings during yacc parsing
ClosedPublic

Authored by jhb on Feb 11 2025, 1:20 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jun 28, 8:12 AM
Unknown Object (File)
Tue, Jun 24, 6:30 AM
Unknown Object (File)
Mon, Jun 23, 11:24 PM
Unknown Object (File)
Sat, Jun 21, 11:28 PM
Unknown Object (File)
Tue, Jun 17, 5:18 AM
Unknown Object (File)
May 11 2025, 3:16 AM
Unknown Object (File)
May 10 2025, 10:40 PM
Unknown Object (File)
Apr 8 2025, 1:00 PM
Subscribers

Details

Summary

The lexer always allocates a duplicate string via strdup for STR
tokens. The parse handlers did not always free these duplicated
strings after consuming them.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb requested review of this revision.Feb 11 2025, 1:20 AM

Did you check for any similar resource leaks in uclparse.c ?

This revision is now accepted and ready to land.Feb 11 2025, 6:20 PM

Did you check for any similar resource leaks in uclparse.c ?

I did not, but AFAIK, the ucl_get_* routines don't return storage to the caller. They seem to be more like nvlist_get_* rather than nvlist_take_*. In particular, the uclparse.c code is already careful to strdup() any strings it wants to save in the configuration.

Note that after my changes later in this series, we always do the same for the yacc/lex parser as well, and we probably could remove the strdup() calls in token.l and all the free() calls in parse.y which would simplify things a bit.