Fix query cache when pgpool is built without memcached.
authorTatsuo Ishii <ishii@postgresql.org>
Fri, 5 Sep 2025 08:12:12 +0000 (17:12 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Fri, 5 Sep 2025 08:55:39 +0000 (17:55 +0900)
When configure is not provided --with-memcached, compiler error
occured.

    query_cache/pool_memqcache.c:542:17: è­Šć‘Š: 'free' called on pointer 'cih' with nonzero offset 24 -Wfree-nonheap-objec
    t]
      542 |                 free(ptr);
          |                 ^~~~~~~~~
    query_cache/pool_memqcache.c:2843:15: ć‚™è€ƒ: returned from 'pool_cache_item_header'
     2843 |         cih = pool_cache_item_header(cacheid);
          |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    This is caused by the code block:
            if (!pool_is_shmem_cache())
            {
                    free(ptr);
            }

The compiler thought that "ptr" could be the value returned by
pool_cache_item_header(), because the compiler does not understand
pool_is_shmem_cache() could return false only when memcached is
enabled. To fix this, surround the code block above with #ifdef
USE_MEMCACHED.

Reported-by: Bo Peng <pengbo@sraoss.co.jp>
Backpatch-through: v4.2

src/query_cache/pool_memqcache.c

index 40ad93e1a5ae8e80fe2d3f2470e578b75d750f6a..ba6b36afa40fe9c0fe90cd075fb7f5f848e92047 100644 (file)
@@ -537,10 +537,12 @@ pool_fetch_cache(POOL_CONNECTION_POOL *backend, const char *query, char **buf, s
 
        memcpy(p, ptr, *len);
 
+#ifdef USE_MEMCACHED
        if (!pool_is_shmem_cache())
        {
                free(ptr);
        }
+#endif
 
        ereport(DEBUG1,
                        (errmsg("fetching from cache storage"),