pgsql: Fix snapshot reference leak if lo_export fails.

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix snapshot reference leak if lo_export fails.
Date: 2021-11-03 09:44:21
Message-ID: E1miCof-0006bt-DZ@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6b1b405ebfdce9da47f59d8d4144b1168709fbce

Modified Files
--------------
src/backend/libpq/be-fsstubs.c | 146 ++++++++++++++---------------
src/backend/storage/large_object/inv_api.c | 27 +++---
src/test/regress/input/largeobject.source | 11 +++
src/test/regress/output/largeobject.source | 11 +++
4 files changed, 104 insertions(+), 91 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Daniel Gustafsson 2021-11-03 11:06:58 Re: pgsql: Fix snapshot reference leak if lo_export fails.
Previous Message Peter Eisentraut 2021-11-03 06:38:12 pgsql: Fix incorrect format placeholder