]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
libctf: don't leak enums if ctf_add_type fails
authorNick Alcock <nick.alcock@oracle.com>
Tue, 11 Jun 2024 19:11:29 +0000 (20:11 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Tue, 18 Jun 2024 12:20:31 +0000 (13:20 +0100)
commit327356780ab4436b59b666a756323b8bda68cbd4
treeeb8be1a75188b04b109abc34f5795250e0ef40ac
parentf8da1a05db64d8c5c700e07a008a1938858a7adf
libctf: don't leak enums if ctf_add_type fails

If ctf_add_type failed in the middle of enumerator addition, the
destination would end up containing the source enum type and some
but not all of its enumerator constants.

Use snapshots to roll back the enum addition as a whole if this happens.
Before now, it's been pretty unlikely, but in an upcoming commit we will ban
addition of enumerators that already exist in a given dict, making failure
of ctf_add_enumerator and thus of this part of ctf_add_type much more
likely.

libctf/
* ctf-create.c (ctf_add_type_internal): Roll back if enum or
          enumerator addition fails.
libctf/ctf-create.c