]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix error handling with threads on OOM in ECPG connection logic
authorMichael Paquier <michael@paquier.xyz>
Mon, 13 Sep 2021 04:24:35 +0000 (13:24 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 13 Sep 2021 04:24:35 +0000 (13:24 +0900)
commitb6a10ff4abe9538f16d9f52bda6bc04f90b77d0d
treef75273c094055c3fd917331f5d74818560554bf5
parent3be381a900df75de6a085cc3a465d85ec8bf39cd
Fix error handling with threads on OOM in ECPG connection logic

An out-of-memory failure happening when allocating the structures to
store the connection parameter keywords and values would mess up with
the set of connections saved, as on failure the pthread mutex would
still be hold with the new connection object listed but free()'d.

Rather than just unlocking the mutex, which would leave the static list
of connections into an inconsistent state, move the allocation for the
structures of the connection parameters before beginning the test
manipulation.  This ensures that the list of connections and the
connection mutex remain consistent all the time in this code path.

This error is unlikely going to happen, but this could mess up badly
with ECPG clients in surprising ways, so backpatch all the way down.

Reported-by: ryancaicse
Discussion: https://postgr.es/m/17186-b4cfd8f0eb4d1dee@postgresql.org
Backpatch-through: 9.6
src/interfaces/ecpg/ecpglib/connect.c