acquire-memory-for-stack.patch

text/x-patch

Filename: acquire-memory-for-stack.patch
Type: text/x-patch
Part: 0
Message: Re: BUG #18374: Printing memory contexts on OOM condition might lead to segmentation fault

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
File+
src/backend/tcop/postgres.c 9 0
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 59ab812d2e..bb9d309f4e 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -3464,6 +3464,14 @@ ProcessInterrupts(void)
 		HandleParallelApplyMessages();
 }
 
+void prepare_stack(int n)
+{
+	char buffer[1024 * 1024];
+	memset(buffer, 0, sizeof(buffer));
+	if (n > 0)
+		prepare_stack(n - 1);
+}
+
 /*
  * set_stack_base: set up reference point for stack depth checking
  *
@@ -3490,6 +3498,7 @@ set_stack_base(void)
 	stack_base_ptr = &stack_base;
 #endif
 
+	prepare_stack((max_stack_depth_bytes + STACK_DEPTH_SLOP) / (1024 * 1024));
 	return old;
 }