Fix error while allocating shared memory.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Wed, 13 Jan 2021 09:49:51 +0000 (18:49 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Wed, 13 Jan 2021 10:25:56 +0000 (19:25 +0900)
If num_init_children * max_pool is huge, pool_coninfo_size() failed to
calculate the size of required shared memory because the data type
used for the variable to store shared memory size was int and it
overflows for too large shared memory size. To fix this change
pool_coninfo_size() to size_t and use appropriate size_t for the
variable used within the function.

Also fix to use proper format qualifier in
pool_shared_memory_create().

src/context/pool_process_context.c
src/include/context/pool_process_context.h
src/utils/pool_shmem.c

index 25de937b827d7b7dafa9e972ea78022977b2e61d..3dfabdd50c3575683f8bd3f74e34705d41b4c836 100644 (file)
@@ -6,7 +6,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL 
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2017     PgPool Global Development Group
+ * Copyright (c) 2003-2021     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -99,16 +99,18 @@ void pool_incremnet_local_session_id(void)
 /*
  * Return byte size of connection info(ConnectionInfo) on shmem.
  */
-int pool_coninfo_size(void)
+size_t
+pool_coninfo_size(void)
 {
-       int size;
+       size_t                  size;
+
        size = pool_config->num_init_children *
                pool_config->max_pool *
                MAX_NUM_BACKENDS *
                sizeof(ConnectionInfo);
 
        ereport(DEBUG1,
-                       (errmsg("pool_coninfo_size: num_init_children (%d) * max_pool (%d) * MAX_NUM_BACKENDS (%d) * sizeof(ConnectionInfo) (%zu) = %d bytes requested for shared memory",
+                       (errmsg("pool_coninfo_size: num_init_children (%d) * max_pool (%d) * MAX_NUM_BACKENDS (%d) * sizeof(ConnectionInfo) (%zu) = %zu bytes requested for shared memory",
                                        pool_config->num_init_children,
                                        pool_config->max_pool,
                                        MAX_NUM_BACKENDS,
index 2e7863b0c77b568b0f149be513fbbbd7422f1ac4..425fdcfe2eb81bf6a74a287121f736dabf1e166c 100644 (file)
@@ -6,7 +6,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL 
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2015     PgPool Global Development Group
+ * Copyright (c) 2003-2021     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -57,10 +57,10 @@ extern void pool_init_process_context(void);
 extern POOL_PROCESS_CONTEXT *pool_get_process_context(void);
 extern ProcessInfo *pool_get_my_process_info(void);
 extern void pool_incremnet_local_session_id(void);
-extern int pool_coninfo_size(void);
 extern int pool_coninfo_num(void);
 extern ConnectionInfo *pool_coninfo(int child, int connection_pool, int backend);
 extern ConnectionInfo *pool_coninfo_pid(int pid, int connection_pool, int backend);
+extern size_t  pool_coninfo_size(void);
 extern void pool_coninfo_set_frontend_connected(int proc_id, int pool_index);
 extern void pool_coninfo_unset_frontend_connected(int proc_id, int pool_index);
 
index 71c5a9876f66083737fcd65b15fa5fe2ba9dd460..340bd63b3ada7113fb3551bc2c58f7fea5cebded 100644 (file)
@@ -5,7 +5,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Portions Copyright (c) 2003-2011, PgPool Global Development Group
+ * Portions Copyright (c) 2003-2021, PgPool Global Development Group
  * Portions Copyright (c) 2003-2004, PostgreSQL Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
@@ -54,8 +54,8 @@ pool_shared_memory_create(size_t size)
 
        if (shmid < 0)
                ereport(FATAL,
-                       (errmsg("could not create shared memory for request size: %ld",size),
-                               errdetail("shared memory creation failed with error \"%s\"",strerror(errno))));
+                               (errmsg("could not create shared memory for request size: %zu", size),
+                                errdetail("shared memory creation failed with error \"%m\"")));
 
        /* Register on-exit routine to delete the new segment */
        on_shmem_exit(IpcMemoryDelete, shmid);