Fix snapshot reference leak if lo_export fails.
Heikki Linnakangas <heikki.linnakangas@iki.fi>
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
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/libpq/be-fsstubs.c | modified | +71 −76 |
| src/backend/storage/large_object/inv_api.c | modified | +16 −20 |
| src/test/regress/input/largeobject.source | modified | +11 −0 |
| src/test/regress/output/largeobject.source | modified | +11 −0 |
Discussion
- Snapshot leak warning with lo_export in subtransaction 5 messages · 2021-09-27 → 2021-11-03