Fix exception safety bug in typcache.c.
authorThomas Munro <tmunro@postgresql.org>
Wed, 13 Sep 2023 02:32:24 +0000 (14:32 +1200)
committerThomas Munro <tmunro@postgresql.org>
Wed, 13 Sep 2023 02:52:34 +0000 (14:52 +1200)
commit6ae57f190e276f46bc2d0b616515bed4b4f664ce
tree545a882a6bc83b1b8874ff985922368c810bd660
parentfeb4e218e5f9d8ec2d0c6f2eac28ad786ea9d79c
Fix exception safety bug in typcache.c.

If an out-of-memory error was thrown at an unfortunate time,
ensure_record_cache_typmod_slot_exists() could leak memory and leave
behind a global state that produced an infinite loop on the next call.

Fix by merging RecordCacheArray and RecordIdentifierArray into a single
array.  With only one allocation or re-allocation, there is no
intermediate state.

Back-patch to all supported releases.

Reported-by: "James Pang (chaolpan)" <chaolpan@cisco.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: http://postgr.es/m/PH0PR11MB519113E738814BDDA702EDADD6EFA%40PH0PR11MB5191.namprd11.prod.outlook.com
src/backend/utils/cache/typcache.c
src/tools/pgindent/typedefs.list