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:56:40 +0000 (17:56 +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 b11d40628820c3b74c92192381854cbd9d01ca57..4906058005aebad312d1a6a31a3b4432e497658e 100644 (file)
@@ -534,10 +534,12 @@ pool_fetch_cache(POOL_CONNECTION_POOL * backend, const char *query, char **buf,
 
        memcpy(p, ptr, *len);
 
+#ifdef USE_MEMCACHED
        if (!pool_is_shmem_cache())
        {
                free(ptr);
        }
+#endif
 
        ereport(DEBUG1,
                        (errmsg("fetching from cache storage"),