diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2021-11-01 16:24:39 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2021-11-01 16:24:39 -0400 |
commit | e9d9ba2a4ddc39e331dd8461b511aa59ec0dc8af (patch) | |
tree | 0ff7b901c0aa98dc474e2fc1029c2e7ada940936 /src/backend/jit/llvm/llvmjit.c | |
parent | 40c516bba864395c77bcfb1bae65ba9562ba8f71 (diff) | |
download | postgresql-e9d9ba2a4ddc39e331dd8461b511aa59ec0dc8af.tar.gz postgresql-e9d9ba2a4ddc39e331dd8461b511aa59ec0dc8af.zip |
Avoid some other O(N^2) hazards in list manipulation.
In the same spirit as 6301c3ada, fix some more places where we were
using list_delete_first() in a loop and thereby risking O(N^2)
behavior. It's not clear that the lists manipulated in these spots
can get long enough to be really problematic ... but it's not clear
that they can't, either, and the fixes are simple enough.
As before, back-patch to v13.
Discussion: https://postgr.es/m/CD2F0E7F-9822-45EC-A411-AE56F14DEA9F@amazon.com
Diffstat (limited to 'src/backend/jit/llvm/llvmjit.c')
-rw-r--r-- | src/backend/jit/llvm/llvmjit.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c index 169dad96d76..fb294495737 100644 --- a/src/backend/jit/llvm/llvmjit.c +++ b/src/backend/jit/llvm/llvmjit.c @@ -171,6 +171,7 @@ static void llvm_release_context(JitContext *context) { LLVMJitContext *llvm_context = (LLVMJitContext *) context; + ListCell *lc; /* * When this backend is exiting, don't clean up LLVM. As an error might @@ -188,12 +189,9 @@ llvm_release_context(JitContext *context) llvm_context->module = NULL; } - while (llvm_context->handles != NIL) + foreach(lc, llvm_context->handles) { - LLVMJitHandle *jit_handle; - - jit_handle = (LLVMJitHandle *) linitial(llvm_context->handles); - llvm_context->handles = list_delete_first(llvm_context->handles); + LLVMJitHandle *jit_handle = (LLVMJitHandle *) lfirst(lc); #if LLVM_VERSION_MAJOR > 11 { @@ -221,6 +219,8 @@ llvm_release_context(JitContext *context) pfree(jit_handle); } + list_free(llvm_context->handles); + llvm_context->handles = NIL; } /* |