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:21:35 +0000 (19:21 +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 baa4d70906f27e2c3286ea031307d50153f82493..56f918d280dc73c5bd2f6a9b271779ea31222821 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
@@ -104,10 +104,10 @@ pool_incremnet_local_session_id(void)
 /*
  * Return byte size of connection info(ConnectionInfo) on shmem.
  */
-int
+size_t
 pool_coninfo_size(void)
 {
-       int                     size;
+       size_t                  size;
 
        size = pool_config->num_init_children *
                pool_config->max_pool *
@@ -115,7 +115,7 @@ pool_coninfo_size(void)
                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 d57bb0511b81d96229ec91ca5a21a8474306914e..646961eb5ebb1377d23e2eaebbc50e076836e555 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
@@ -59,7 +59,7 @@ 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 size_t  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);
index 787db3f15d8d5e2b72e3bc44cb7cdaf014a9d6dc..c46d9c5415a79a7e648d77d8747faaa8a98178f2 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,7 +54,7 @@ pool_shared_memory_create(size_t size)
 
        if (shmid < 0)
                ereport(FATAL,
-                               (errmsg("could not create shared memory for request size: %ld", size),
+                               (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 */