[bug fix] Fix the size calculation for shmem TOC
Hello,
The attached patch fixes a trivial mistake in the calculation of shmem TOC. The original code allocates unduly large memory because it adds the result of add_size() to its left argument.
Regards
Takayuki Tsunakawa
Attachments:
0001-Fix-size-calculation-for-shmem-TOC.patchapplication/octet-stream; name=0001-Fix-size-calculation-for-shmem-TOC.patchDownload
From 13a3dce6a1df3f835c688bd09634c19adbd9c558 Mon Sep 17 00:00:00 2001
From: Takayuki Tsunakawa <tsunakawa.takay@fujitsu.com>
Date: Thu, 14 Jan 2021 17:33:55 +0900
Subject: [PATCH] Fix size calculation for shmem TOC
---
src/backend/storage/ipc/shm_toc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/backend/storage/ipc/shm_toc.c b/src/backend/storage/ipc/shm_toc.c
index bdd72c4..2d865fa 100644
--- a/src/backend/storage/ipc/shm_toc.c
+++ b/src/backend/storage/ipc/shm_toc.c
@@ -265,8 +265,8 @@ shm_toc_estimate(shm_toc_estimator *e)
Size sz;
sz = offsetof(shm_toc, toc_entry);
- sz += add_size(sz, mul_size(e->number_of_keys, sizeof(shm_toc_entry)));
- sz += add_size(sz, e->space_for_chunks);
+ sz = add_size(sz, mul_size(e->number_of_keys, sizeof(shm_toc_entry)));
+ sz = add_size(sz, e->space_for_chunks);
return BUFFERALIGN(sz);
}
--
2.10.1
On 2021/01/14 17:47, tsunakawa.takay@fujitsu.com wrote:
Hello,
The attached patch fixes a trivial mistake in the calculation of shmem TOC. The original code allocates unduly large memory because it adds the result of add_size() to its left argument.
Thanks for the report and patch! The patch looks good to me.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
On 2021/01/14 18:15, Fujii Masao wrote:
On 2021/01/14 17:47, tsunakawa.takay@fujitsu.com wrote:
Hello,
The attached patch fixes a trivial mistake in the calculation of shmem TOC. The original code allocates unduly large memory because it adds the result of add_size() to its left argument.
Thanks for the report and patch! The patch looks good to me.
Pushed and back-patched to v11. Thanks!
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION