On Thu, 30 Mar 2023 at 22:21, PG Bug reporting form
<noreply@postgresql.org> wrote:
> CREATE TABLE mytable1(id INT GENERATED ALWAYS AS IDENTITY (SEQUENCE NAME
> test_seq));
> We have identified the root cause as follows:
> In the generateSerialExtraStmts function, the memory space for the seqoption
> list has been freed, but the options member of the Constraint still points
> to that memory address, which caused an error during the copyObject
> operation in the EventTriggerCollectSimpleCommand function.
Thank you for the detailed report and reproducer.
The problem seems to be down to generateSerialExtraStmts() deleting a
cell out of the given seqoptions resulting in that becoming an empty
list, but the calling function does not have its list pointer set to
NIL.
I see a few ways to fix; 1) always make a list_copy() of the list
before calling generateSerialExtraStmts(), or; 2) make a copy of the
list inside generateSerialExtraStmts() unconditionally, or 3) at the
very least, just make a copy before calling list_delete_nth_cell().
#1 and #2 might be a bit more effort than is really required, so the
attached does #3.
David