Skip to content

Commit ed3ed3d

Browse files
author
Marcus Pousette
committed
Improve MemoryContext management to prevent memory exhaustion between queries
1 parent d7577b6 commit ed3ed3d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pglite-wasm/pg_main.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,18 @@
2828

2929
// globals
3030

31-
#define MemoryContextResetAndDeleteChildren(...)
31+
/*
32+
* Ensure MessageContext and its children are actually cleared between
33+
* queries. Leaving this as a no-op causes unbounded growth in
34+
* MessageContext when large query strings or parameters are processed,
35+
* eventually exhausting memory.
36+
*/
37+
#undef MemoryContextResetAndDeleteChildren
38+
#define MemoryContextResetAndDeleteChildren(ctx) \
39+
do { \
40+
MemoryContextDeleteChildren((ctx)); \
41+
MemoryContextReset((ctx)); \
42+
} while (0)
3243
// #define SpinLockInit(...)
3344

3445

0 commit comments

Comments
 (0)