If we already have an extension_state array but see a new extension_id
much larger than the highest the extension_id we've previously seen,
the old code might have failed to expand the array to a large enough
size, leading to disaster. Also, if we don't have an extension array
at all and need to create one, we should make sure that it's big enough
that we don't have to resize it instantly.
Reported-by: Tom Lane <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: http://postgr.es/m/
2949591.
1758570711@sss.pgh.pa.us
Backpatch-through: 18
/* If there is no array yet, create one. */
if (es->extension_state == NULL)
{
- es->extension_state_allocated = 16;
+ es->extension_state_allocated =
+ Max(16, pg_nextpower2_32(extension_id + 1));
es->extension_state =
palloc0(es->extension_state_allocated * sizeof(void *));
}
{
int i;
- i = pg_nextpower2_32(es->extension_state_allocated + 1);
+ i = pg_nextpower2_32(extension_id + 1);
es->extension_state = (void **)
repalloc0(es->extension_state,
es->extension_state_allocated * sizeof(void *),