https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94158 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- A pointer returned from strdup has to be valid to be able pass to free. Your testcase makes that invalid.