]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix snapshot reference leak if lo_export fails.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 3 Nov 2021 08:28:52 +0000 (10:28 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 3 Nov 2021 08:54:42 +0000 (10:54 +0200)
commit6bf00da1153607c223cb4cd1be92355233b090ca
tree3d424f2f8f5e04f19dff533f88c061f8103c3a27
parent5ef21004750588e39e853baeeeca8b0a9792b391
Fix snapshot reference leak if lo_export fails.

If lo_export() fails to open the target file or to write to it, it leaks
the created LargeObjectDesc and its snapshot in the top-transaction
context and resource owner. That's pretty harmless, it's a small leak
after all, but it gives the user a "Snapshot reference leak" warning.

Fix by using a short-lived memory context and no resource owner for
transient LargeObjectDescs that are opened and closed within one function
call. The leak is easiest to reproduce with lo_export() on a directory
that doesn't exist, but in principle the other lo_* functions could also
fail.

Backpatch to all supported versions.

Reported-by: Andrew B
Reviewed-by: Alvaro Herrera
Discussion: https://www.postgresql.org/message-id/32bf767a-2d65-71c4-f170-122f416bab7e@iki.fi
src/backend/libpq/be-fsstubs.c
src/backend/storage/large_object/inv_api.c
src/test/regress/input/largeobject.source
src/test/regress/output/largeobject.source