Fix memory leak in "batch" mode in extended query.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Thu, 28 Mar 2019 04:58:27 +0000 (13:58 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Thu, 28 Mar 2019 04:58:27 +0000 (13:58 +0900)
commit56a6b6a72c76eef15f98962e3f85ebc30cc58bd7
tree989d256e2182518096299db2901271952932f546
parentf4f6c852bbeed482eb86f2f9b35a0d40d64ce48c
Fix memory leak in "batch" mode in extended query.

In "batch" mode, not for every execute message, a sync message is
followed.  Unfortunately Pgpool-II only discard memory of query
context for the last execute message while processing the ready for
query message. For example if 3 execute messages are sent before the
sync message, 2 of query context memory will not be freed and this
leads to serious memory leak.

To fix the problem, now the query context memory is possibly discarded
when a command complete message is returned from backend if the query
context is not referenced either by sent messages or pending messages.
If it is not referenced at all, we can discard the query context.

Also even if it is referenced, it is ok to discard the query context
if it is either an unnamed statement or an unnamed portal because it
will be discarded anyway when next unnamed statement or portal is
created.

Per bug 468.
src/context/pool_query_context.c
src/context/pool_session_context.c
src/include/context/pool_session_context.h
src/protocol/CommandComplete.c