From 162aa47c31a0236d68b68d65df3fef0079af0d48 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Wed, 5 Jul 2023 13:13:13 +0300 Subject: [PATCH] Fix leak of LLVM "fatal-on-oom" section counter. llvm_release_context() called llvm_enter_fatal_on_oom(), but was missing the corresponding llvm_leave_fatal_on_oom() call. As a result, if JIT was used at all, we were almost always in the "fatal-on-oom" state. It only makes a difference if you use an extension written in C++, and run out of memory in a C++ 'new' call. In that case, you would get a PostgreSQL FATAL error, instead of the default behavior of throwing a C++ exception. Back-patch to all supported versions. Reviewed-by: Daniel Gustafsson Discussion: https://www.postgresql.org/message-id/54b78cca-bc84-dad8-4a7e-5b56f764fab5@iki.fi --- src/backend/jit/llvm/llvmjit.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c index 537e0c448a..67ebf6248e 100644 --- a/src/backend/jit/llvm/llvmjit.c +++ b/src/backend/jit/llvm/llvmjit.c @@ -233,6 +233,8 @@ llvm_release_context(JitContext *context) pfree(jit_handle); } + + llvm_leave_fatal_on_oom(); } /*