https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120985
Bug ID: 120985 Summary: Possible memory leak in read_specs at gcc.cc Product: gcc Version: 16.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: driver Assignee: unassigned at gcc dot gnu.org Reporter: shuhaofu.g at gmail dot com Target Milestone: --- Affected Commit: 559ddecabef9c23210c84fdb05fceaf9cee81bd9 @ github mirror Affected Function: read_specs @ gcc.cc 1. `save_string` executes and returns a heap-allocated buffer to `suffix` Line: https://github.com/gcc-mirror/gcc/blob/559ddecabef9c23210c84fdb05fceaf9cee81bd9/gcc/gcc.cc#L2559) 2. selects true branch here `suffix[0] == '*'` Line: https://github.com/gcc-mirror/gcc/blob/559ddecabef9c23210c84fdb05fceaf9cee81bd9/gcc/gcc.cc#L2592 After the above branch, `suffix` is neither saved into a global variable nor freed manually. Given that such a leak lies in a while loop, it seems worth fixing. If confirmed, it may also be easily fixed by inserting `free(suffix)` before https://github.com/gcc-mirror/gcc/blob/559ddecabef9c23210c84fdb05fceaf9cee81bd9/gcc/gcc.cc#L2616, without hurting the readability.