The cause can be specified as two things below.
The above case may cause continuous memory growth of the backend process.
The cases below cause the same query and plan to produce multiple result records.
There is already a fixed code for this issue.
Can I send you a Pull-Request?
I've attached the valgrind report below.
==00:00:00:19.958 21739== Memcheck, a memory error detector
==00:00:00:19.958 21739== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==00:00:00:19.958 21739== Using Valgrind-3.24.0 and LibVEX; rerun with -h for copyright info
==00:00:00:19.958 21739== Command: postgres -D /var/lib/pgsql/17/data
==00:00:00:19.958 21739== Parent PID: 21648
==00:00:00:19.958 21739==
==00:00:00:20.957 21739== Conditional jump or move depends on uninitialised value(s)
==00:00:00:20.957 21739== at 0xC05363: calc_bucket (dynahash.c:924)
==00:00:00:20.957 21739== by 0xC06965: hash_initial_lookup (dynahash.c:1722)
==00:00:00:20.957 21739== by 0xC0549F: hash_search_with_hash_value (dynahash.c:1010)
==00:00:00:20.957 21739== by 0xC053CD: hash_search (dynahash.c:961)
==00:00:00:20.957 21739== by 0x85CDEAB: pgsp_store (pg_store_plans.c:1263)
==00:00:00:20.957 21739== by 0x85CD91D: pgsp_ExecutorEnd (pg_store_plans.c:1109)
==00:00:00:20.957 21739== by 0x769857: ExecutorEnd (execMain.c:464)
==00:00:00:20.957 21739== by 0x6E1953: PortalCleanup (portalcmds.c:299)
==00:00:00:20.957 21739== by 0xC38D99: PortalDrop (portalmem.c:502)
==00:00:00:20.957 21739== by 0xA0554D: exec_simple_query (postgres.c:1288)
==00:00:00:20.957 21739== by 0xA0A77A: PostgresMain (postgres.c:4767)
==00:00:00:20.957 21739== by 0xA01365: BackendMain (backend_startup.c:105)
==00:00:00:20.957 21739== by 0x92D88D: postmaster_child_launch (launch_backend.c:277)
==00:00:00:20.957 21739== by 0x9339EE: BackendStartup (postmaster.c:3594)
==00:00:00:20.957 21739== by 0x930C2A: ServerLoop (postmaster.c:1676)
==00:00:00:20.957 21739== by 0x9304FB: PostmasterMain (postmaster.c:1374)
==00:00:00:20.957 21739== by 0x7F118B: main (main.c:199)
==00:00:00:20.957 21739==
==00:00:00:20.957 21739== Use of uninitialised value of size 8
==00:00:00:20.957 21739== at 0xC069A8: hash_initial_lookup (dynahash.c:1727)
==00:00:00:20.957 21739== by 0xC0549F: hash_search_with_hash_value (dynahash.c:1010)
==00:00:00:20.957 21739== by 0xC053CD: hash_search (dynahash.c:961)
==00:00:00:20.957 21739== by 0x85CDEAB: pgsp_store (pg_store_plans.c:1263)
==00:00:00:20.957 21739== by 0x85CD91D: pgsp_ExecutorEnd (pg_store_plans.c:1109)
==00:00:00:20.957 21739== by 0x769857: ExecutorEnd (execMain.c:464)
==00:00:00:20.957 21739== by 0x6E1953: PortalCleanup (portalcmds.c:299)
==00:00:00:20.957 21739== by 0xC38D99: PortalDrop (portalmem.c:502)
==00:00:00:20.957 21739== by 0xA0554D: exec_simple_query (postgres.c:1288)
==00:00:00:20.957 21739== by 0xA0A77A: PostgresMain (postgres.c:4767)
==00:00:00:20.957 21739== by 0xA01365: BackendMain (backend_startup.c:105)
==00:00:00:20.957 21739== by 0x92D88D: postmaster_child_launch (launch_backend.c:277)
==00:00:00:20.957 21739== by 0x9339EE: BackendStartup (postmaster.c:3594)
==00:00:00:20.957 21739== by 0x930C2A: ServerLoop (postmaster.c:1676)
==00:00:00:20.957 21739== by 0x9304FB: PostmasterMain (postmaster.c:1374)
==00:00:00:20.957 21739== by 0x7F118B: main (main.c:199)
==00:00:00:20.957 21739==
==00:00:00:20.957 21739== Use of uninitialised value of size 8
==00:00:00:20.957 21739== at 0xC054A4: hash_search_with_hash_value (dynahash.c:1011)
==00:00:00:20.957 21739== by 0xC053CD: hash_search (dynahash.c:961)
==00:00:00:20.957 21739== by 0x85CDEAB: pgsp_store (pg_store_plans.c:1263)
==00:00:00:20.957 21739== by 0x85CD91D: pgsp_ExecutorEnd (pg_store_plans.c:1109)
==00:00:00:20.957 21739== by 0x769857: ExecutorEnd (execMain.c:464)
==00:00:00:20.957 21739== by 0x6E1953: PortalCleanup (portalcmds.c:299)
==00:00:00:20.957 21739== by 0xC38D99: PortalDrop (portalmem.c:502)
==00:00:00:20.957 21739== by 0xA0554D: exec_simple_query (postgres.c:1288)
==00:00:00:20.957 21739== by 0xA0A77A: PostgresMain (postgres.c:4767)
==00:00:00:20.957 21739== by 0xA01365: BackendMain (backend_startup.c:105)
==00:00:00:20.957 21739== by 0x92D88D: postmaster_child_launch (launch_backend.c:277)
==00:00:00:20.957 21739== by 0x9339EE: BackendStartup (postmaster.c:3594)
==00:00:00:20.957 21739== by 0x930C2A: ServerLoop (postmaster.c:1676)
==00:00:00:20.957 21739== by 0x9304FB: PostmasterMain (postmaster.c:1374)
==00:00:00:20.957 21739== by 0x7F118B: main (main.c:199)
==00:00:00:20.957 21739==
==00:00:00:20.959 21739== Use of uninitialised value of size 8
==00:00:00:20.959 21739== at 0xC069A8: hash_initial_lookup (dynahash.c:1727)
==00:00:00:20.959 21739== by 0xC0549F: hash_search_with_hash_value (dynahash.c:1010)
==00:00:00:20.959 21739== by 0xC053CD: hash_search (dynahash.c:961)
==00:00:00:20.959 21739== by 0x85CF7FB: entry_alloc (pg_store_plans.c:1822)
==00:00:00:20.959 21739== by 0x85CDF79: pgsp_store (pg_store_plans.c:1304)
==00:00:00:20.959 21739== by 0x85CD91D: pgsp_ExecutorEnd (pg_store_plans.c:1109)
==00:00:00:20.959 21739== by 0x769857: ExecutorEnd (execMain.c:464)
==00:00:00:20.959 21739== by 0x6E1953: PortalCleanup (portalcmds.c:299)
==00:00:00:20.959 21739== by 0xC38D99: PortalDrop (portalmem.c:502)
==00:00:00:20.959 21739== by 0xA0554D: exec_simple_query (postgres.c:1288)
==00:00:00:20.959 21739== by 0xA0A77A: PostgresMain (postgres.c:4767)
==00:00:00:20.959 21739== by 0xA01365: BackendMain (backend_startup.c:105)
==00:00:00:20.959 21739== by 0x92D88D: postmaster_child_launch (launch_backend.c:277)
==00:00:00:20.959 21739== by 0x9339EE: BackendStartup (postmaster.c:3594)
==00:00:00:20.959 21739== by 0x930C2A: ServerLoop (postmaster.c:1676)
==00:00:00:20.959 21739== by 0x9304FB: PostmasterMain (postmaster.c:1374)
==00:00:00:20.959 21739== by 0x7F118B: main (main.c:199)
==00:00:00:20.959 21739==
==00:00:00:20.959 21739== Use of uninitialised value of size 8
==00:00:00:20.959 21739== at 0xC054A4: hash_search_with_hash_value (dynahash.c:1011)
==00:00:00:20.959 21739== by 0xC053CD: hash_search (dynahash.c:961)
==00:00:00:20.959 21739== by 0x85CF7FB: entry_alloc (pg_store_plans.c:1822)
==00:00:00:20.959 21739== by 0x85CDF79: pgsp_store (pg_store_plans.c:1304)
==00:00:00:20.959 21739== by 0x85CD91D: pgsp_ExecutorEnd (pg_store_plans.c:1109)
==00:00:00:20.959 21739== by 0x769857: ExecutorEnd (execMain.c:464)
==00:00:00:20.959 21739== by 0x6E1953: PortalCleanup (portalcmds.c:299)
==00:00:00:20.959 21739== by 0xC38D99: PortalDrop (portalmem.c:502)
==00:00:00:20.959 21739== by 0xA0554D: exec_simple_query (postgres.c:1288)
==00:00:00:20.959 21739== by 0xA0A77A: PostgresMain (postgres.c:4767)
==00:00:00:20.959 21739== by 0xA01365: BackendMain (backend_startup.c:105)
==00:00:00:20.959 21739== by 0x92D88D: postmaster_child_launch (launch_backend.c:277)
==00:00:00:20.959 21739== by 0x9339EE: BackendStartup (postmaster.c:3594)
==00:00:00:20.959 21739== by 0x930C2A: ServerLoop (postmaster.c:1676)
==00:00:00:20.959 21739== by 0x9304FB: PostmasterMain (postmaster.c:1374)
==00:00:00:20.959 21739== by 0x7F118B: main (main.c:199)
==00:00:00:20.959 21739==
==00:00:00:20.959 21739== Use of uninitialised value of size 8
==00:00:00:20.959 21739== at 0xC05827: hash_search_with_hash_value (dynahash.c:1104)
==00:00:00:20.959 21739== by 0xC053CD: hash_search (dynahash.c:961)
==00:00:00:20.959 21739== by 0x85CF7FB: entry_alloc (pg_store_plans.c:1822)
==00:00:00:20.959 21739== by 0x85CDF79: pgsp_store (pg_store_plans.c:1304)
==00:00:00:20.959 21739== by 0x85CD91D: pgsp_ExecutorEnd (pg_store_plans.c:1109)
==00:00:00:20.959 21739== by 0x769857: ExecutorEnd (execMain.c:464)
==00:00:00:20.959 21739== by 0x6E1953: PortalCleanup (portalcmds.c:299)
==00:00:00:20.959 21739== by 0xC38D99: PortalDrop (portalmem.c:502)
==00:00:00:20.959 21739== by 0xA0554D: exec_simple_query (postgres.c:1288)
==00:00:00:20.959 21739== by 0xA0A77A: PostgresMain (postgres.c:4767)
==00:00:00:20.959 21739== by 0xA01365: BackendMain (backend_startup.c:105)
==00:00:00:20.959 21739== by 0x92D88D: postmaster_child_launch (launch_backend.c:277)
==00:00:00:20.959 21739== by 0x9339EE: BackendStartup (postmaster.c:3594)
==00:00:00:20.959 21739== by 0x930C2A: ServerLoop (postmaster.c:1676)
==00:00:00:20.959 21739== by 0x9304FB: PostmasterMain (postmaster.c:1374)
==00:00:00:20.959 21739== by 0x7F118B: main (main.c:199)
==00:00:00:20.959 21739==
==00:00:00:21.062 21739== Use of uninitialised value of size 8
==00:00:00:21.062 21739== at 0xC069A8: hash_initial_lookup (dynahash.c:1727)
==00:00:00:21.062 21739== by 0xC0549F: hash_search_with_hash_value (dynahash.c:1010)
==00:00:00:21.062 21739== by 0xC053CD: hash_search (dynahash.c:961)
==00:00:00:21.062 21739== by 0x85D08C1: entry_reset (pg_store_plans.c:2384)
==00:00:00:21.062 21739== by 0x85CE541: pg_store_plans_reset (pg_store_plans.c:1417)
==00:00:00:21.062 21739== by 0x777590: ExecMakeTableFunctionResult (execSRF.c:234)
==00:00:00:21.062 21739== by 0x791844: FunctionNext (nodeFunctionscan.c:94)
==00:00:00:21.062 21739== by 0x778EC0: ExecScanFetch (execScan.c:131)
==00:00:00:21.062 21739== by 0x778F39: ExecScan (execScan.c:180)
==00:00:00:21.062 21739== by 0x791BE1: ExecFunctionScan (nodeFunctionscan.c:269)
==00:00:00:21.062 21739== by 0x774CB2: ExecProcNodeFirst (execProcnode.c:464)
==00:00:00:21.062 21739== by 0x769172: ExecProcNode.lto_priv.0 (executor.h:274)
==00:00:00:21.062 21739== by 0x76B85D: ExecutePlan (execMain.c:1649)
==00:00:00:21.062 21739== by 0x769688: standard_ExecutorRun (execMain.c:361)
==00:00:00:21.062 21739== by 0x85CD4AF: pgsp_ExecutorRun (pg_store_plans.c:1013)
==00:00:00:21.062 21739== by 0x85F03B2: pgeq_ExecutorRun (pg_ensure_queryid.c:75)
==00:00:00:21.062 21739== by 0x769574: ExecutorRun (execMain.c:305)
==00:00:00:21.062 21739== by 0xA0CA80: PortalRunSelect (pquery.c:922)
==00:00:00:21.062 21739== by 0xA0C6EA: PortalRun (pquery.c:766)
==00:00:00:21.062 21739== by 0xA05527: exec_simple_query (postgres.c:1278)
==00:00:00:21.062 21739== by 0xA0A77A: PostgresMain (postgres.c:4767)
==00:00:00:21.062 21739== by 0xA01365: BackendMain (backend_startup.c:105)
==00:00:00:21.062 21739== by 0x92D88D: postmaster_child_launch (launch_backend.c:277)
==00:00:00:21.062 21739== by 0x9339EE: BackendStartup (postmaster.c:3594)
==00:00:00:21.062 21739== by 0x930C2A: ServerLoop (postmaster.c:1676)
==00:00:00:21.062 21739== by 0x9304FB: PostmasterMain (postmaster.c:1374)
==00:00:00:21.062 21739== by 0x7F118B: main (main.c:199)
==00:00:00:21.062 21739==
==00:00:00:21.062 21739== Use of uninitialised value of size 8
==00:00:00:21.062 21739== at 0xC054A4: hash_search_with_hash_value (dynahash.c:1011)
==00:00:00:21.062 21739== by 0xC053CD: hash_search (dynahash.c:961)
==00:00:00:21.062 21739== by 0x85D08C1: entry_reset (pg_store_plans.c:2384)
==00:00:00:21.062 21739== by 0x85CE541: pg_store_plans_reset (pg_store_plans.c:1417)
==00:00:00:21.062 21739== by 0x777590: ExecMakeTableFunctionResult (execSRF.c:234)
==00:00:00:21.062 21739== by 0x791844: FunctionNext (nodeFunctionscan.c:94)
==00:00:00:21.062 21739== by 0x778EC0: ExecScanFetch (execScan.c:131)
==00:00:00:21.062 21739== by 0x778F39: ExecScan (execScan.c:180)
==00:00:00:21.062 21739== by 0x791BE1: ExecFunctionScan (nodeFunctionscan.c:269)
==00:00:00:21.062 21739== by 0x774CB2: ExecProcNodeFirst (execProcnode.c:464)
==00:00:00:21.062 21739== by 0x769172: ExecProcNode.lto_priv.0 (executor.h:274)
==00:00:00:21.062 21739== by 0x76B85D: ExecutePlan (execMain.c:1649)
==00:00:00:21.062 21739== by 0x769688: standard_ExecutorRun (execMain.c:361)
==00:00:00:21.062 21739== by 0x85CD4AF: pgsp_ExecutorRun (pg_store_plans.c:1013)
==00:00:00:21.062 21739== by 0x85F03B2: pgeq_ExecutorRun (pg_ensure_queryid.c:75)
==00:00:00:21.062 21739== by 0x769574: ExecutorRun (execMain.c:305)
==00:00:00:21.062 21739== by 0xA0CA80: PortalRunSelect (pquery.c:922)
==00:00:00:21.062 21739== by 0xA0C6EA: PortalRun (pquery.c:766)
==00:00:00:21.062 21739== by 0xA05527: exec_simple_query (postgres.c:1278)
==00:00:00:21.062 21739== by 0xA0A77A: PostgresMain (postgres.c:4767)
==00:00:00:21.062 21739== by 0xA01365: BackendMain (backend_startup.c:105)
==00:00:00:21.062 21739== by 0x92D88D: postmaster_child_launch (launch_backend.c:277)
==00:00:00:21.062 21739== by 0x9339EE: BackendStartup (postmaster.c:3594)
==00:00:00:21.062 21739== by 0x930C2A: ServerLoop (postmaster.c:1676)
==00:00:00:21.062 21739== by 0x9304FB: PostmasterMain (postmaster.c:1374)
==00:00:00:21.062 21739== by 0x7F118B: main (main.c:199)
==00:00:00:21.062 21739==
==00:00:00:21.062 21739== Conditional jump or move depends on uninitialised value(s)
==00:00:00:21.062 21739== at 0xC054CF: hash_search_with_hash_value (dynahash.c:1021)
==00:00:00:21.062 21739== by 0xC053CD: hash_search (dynahash.c:961)
==00:00:00:21.062 21739== by 0x85D08C1: entry_reset (pg_store_plans.c:2384)
==00:00:00:21.062 21739== by 0x85CE541: pg_store_plans_reset (pg_store_plans.c:1417)
==00:00:00:21.062 21739== by 0x777590: ExecMakeTableFunctionResult (execSRF.c:234)
==00:00:00:21.062 21739== by 0x791844: FunctionNext (nodeFunctionscan.c:94)
==00:00:00:21.062 21739== by 0x778EC0: ExecScanFetch (execScan.c:131)
==00:00:00:21.062 21739== by 0x778F39: ExecScan (execScan.c:180)
==00:00:00:21.062 21739== by 0x791BE1: ExecFunctionScan (nodeFunctionscan.c:269)
==00:00:00:21.062 21739== by 0x774CB2: ExecProcNodeFirst (execProcnode.c:464)
==00:00:00:21.062 21739== by 0x769172: ExecProcNode.lto_priv.0 (executor.h:274)
==00:00:00:21.062 21739== by 0x76B85D: ExecutePlan (execMain.c:1649)
==00:00:00:21.062 21739== by 0x769688: standard_ExecutorRun (execMain.c:361)
==00:00:00:21.062 21739== by 0x85CD4AF: pgsp_ExecutorRun (pg_store_plans.c:1013)
==00:00:00:21.062 21739== by 0x85F03B2: pgeq_ExecutorRun (pg_ensure_queryid.c:75)
==00:00:00:21.062 21739== by 0x769574: ExecutorRun (execMain.c:305)
==00:00:00:21.062 21739== by 0xA0CA80: PortalRunSelect (pquery.c:922)
==00:00:00:21.062 21739== by 0xA0C6EA: PortalRun (pquery.c:766)
==00:00:00:21.062 21739== by 0xA05527: exec_simple_query (postgres.c:1278)
==00:00:00:21.062 21739== by 0xA0A77A: PostgresMain (postgres.c:4767)
==00:00:00:21.062 21739== by 0xA01365: BackendMain (backend_startup.c:105)
==00:00:00:21.062 21739== by 0x92D88D: postmaster_child_launch (launch_backend.c:277)
==00:00:00:21.062 21739== by 0x9339EE: BackendStartup (postmaster.c:3594)
==00:00:00:21.062 21739== by 0x930C2A: ServerLoop (postmaster.c:1676)
==00:00:00:21.062 21739== by 0x9304FB: PostmasterMain (postmaster.c:1374)
==00:00:00:21.062 21739== by 0x7F118B: main (main.c:199)
==00:00:00:21.062 21739==
==00:00:00:21.062 21739== Conditional jump or move depends on uninitialised value(s)
==00:00:00:21.062 21739== at 0x485137E: bcmp (vg_replace_strmem.c:1233)
==00:00:00:21.062 21739== by 0xC054E9: hash_search_with_hash_value (dynahash.c:1022)
==00:00:00:21.062 21739== by 0xC053CD: hash_search (dynahash.c:961)
==00:00:00:21.062 21739== by 0x85D08C1: entry_reset (pg_store_plans.c:2384)
==00:00:00:21.062 21739== by 0x85CE541: pg_store_plans_reset (pg_store_plans.c:1417)
==00:00:00:21.062 21739== by 0x777590: ExecMakeTableFunctionResult (execSRF.c:234)
==00:00:00:21.062 21739== by 0x791844: FunctionNext (nodeFunctionscan.c:94)
==00:00:00:21.062 21739== by 0x778EC0: ExecScanFetch (execScan.c:131)
==00:00:00:21.062 21739== by 0x778F39: ExecScan (execScan.c:180)
==00:00:00:21.062 21739== by 0x791BE1: ExecFunctionScan (nodeFunctionscan.c:269)
==00:00:00:21.062 21739== by 0x774CB2: ExecProcNodeFirst (execProcnode.c:464)
==00:00:00:21.062 21739== by 0x769172: ExecProcNode.lto_priv.0 (executor.h:274)
==00:00:00:21.062 21739== by 0x76B85D: ExecutePlan (execMain.c:1649)
==00:00:00:21.062 21739== by 0x769688: standard_ExecutorRun (execMain.c:361)
==00:00:00:21.062 21739== by 0x85CD4AF: pgsp_ExecutorRun (pg_store_plans.c:1013)
==00:00:00:21.062 21739== by 0x85F03B2: pgeq_ExecutorRun (pg_ensure_queryid.c:75)
==00:00:00:21.062 21739== by 0x769574: ExecutorRun (execMain.c:305)
==00:00:00:21.062 21739== by 0xA0CA80: PortalRunSelect (pquery.c:922)
==00:00:00:21.062 21739== by 0xA0C6EA: PortalRun (pquery.c:766)
==00:00:00:21.062 21739== by 0xA05527: exec_simple_query (postgres.c:1278)
==00:00:00:21.062 21739== by 0xA0A77A: PostgresMain (postgres.c:4767)
==00:00:00:21.062 21739== by 0xA01365: BackendMain (backend_startup.c:105)
==00:00:00:21.062 21739== by 0x92D88D: postmaster_child_launch (launch_backend.c:277)
==00:00:00:21.062 21739== by 0x9339EE: BackendStartup (postmaster.c:3594)
==00:00:00:21.062 21739== by 0x930C2A: ServerLoop (postmaster.c:1676)
==00:00:00:21.062 21739== by 0x9304FB: PostmasterMain (postmaster.c:1374)
==00:00:00:21.062 21739== by 0x7F118B: main (main.c:199)
==00:00:00:21.062 21739==
==00:00:00:21.062 21739== Use of uninitialised value of size 8
==00:00:00:21.062 21739== at 0xC05641: hash_search_with_hash_value (dynahash.c:1057)
==00:00:00:21.062 21739== by 0xC053CD: hash_search (dynahash.c:961)
==00:00:00:21.062 21739== by 0x85D08C1: entry_reset (pg_store_plans.c:2384)
==00:00:00:21.062 21739== by 0x85CE541: pg_store_plans_reset (pg_store_plans.c:1417)
==00:00:00:21.062 21739== by 0x777590: ExecMakeTableFunctionResult (execSRF.c:234)
==00:00:00:21.062 21739== by 0x791844: FunctionNext (nodeFunctionscan.c:94)
==00:00:00:21.062 21739== by 0x778EC0: ExecScanFetch (execScan.c:131)
==00:00:00:21.062 21739== by 0x778F39: ExecScan (execScan.c:180)
==00:00:00:21.062 21739== by 0x791BE1: ExecFunctionScan (nodeFunctionscan.c:269)
==00:00:00:21.062 21739== by 0x774CB2: ExecProcNodeFirst (execProcnode.c:464)
==00:00:00:21.062 21739== by 0x769172: ExecProcNode.lto_priv.0 (executor.h:274)
==00:00:00:21.062 21739== by 0x76B85D: ExecutePlan (execMain.c:1649)
==00:00:00:21.062 21739== by 0x769688: standard_ExecutorRun (execMain.c:361)
==00:00:00:21.062 21739== by 0x85CD4AF: pgsp_ExecutorRun (pg_store_plans.c:1013)
==00:00:00:21.062 21739== by 0x85F03B2: pgeq_ExecutorRun (pg_ensure_queryid.c:75)
==00:00:00:21.062 21739== by 0x769574: ExecutorRun (execMain.c:305)
==00:00:00:21.062 21739== by 0xA0CA80: PortalRunSelect (pquery.c:922)
==00:00:00:21.062 21739== by 0xA0C6EA: PortalRun (pquery.c:766)
==00:00:00:21.062 21739== by 0xA05527: exec_simple_query (postgres.c:1278)
==00:00:00:21.062 21739== by 0xA0A77A: PostgresMain (postgres.c:4767)
==00:00:00:21.062 21739== by 0xA01365: BackendMain (backend_startup.c:105)
==00:00:00:21.062 21739== by 0x92D88D: postmaster_child_launch (launch_backend.c:277)
==00:00:00:21.062 21739== by 0x9339EE: BackendStartup (postmaster.c:3594)
==00:00:00:21.062 21739== by 0x930C2A: ServerLoop (postmaster.c:1676)
==00:00:00:21.062 21739== by 0x9304FB: PostmasterMain (postmaster.c:1374)
==00:00:00:21.062 21739== by 0x7F118B: main (main.c:199)
==00:00:00:21.062 21739==
==00:00:00:21.349 21739== HEAP SUMMARY:
==00:00:00:21.349 21739== in use at exit: 1,318,037 bytes in 309 blocks
==00:00:00:21.349 21739== total heap usage: 17,907 allocs, 6,972 frees, 10,004,680 bytes allocated
==00:00:00:21.349 21739==
==00:00:00:21.654 21739== 241 bytes in 1 blocks are definitely lost in loss record 280 of 472
==00:00:00:21.654 21739== at 0x484482F: malloc (vg_replace_malloc.c:446)
==00:00:00:21.654 21739== by 0x85CFF91: ptext_load_file (pg_store_plans.c:2068)
==00:00:00:21.654 21739== by 0x85CE946: pg_store_plans_internal (pg_store_plans.c:1536)
==00:00:00:21.654 21739== by 0x85CE569: pg_store_plans_1_9 (pg_store_plans.c:1434)
==00:00:00:21.655 21739== by 0x777590: ExecMakeTableFunctionResult (execSRF.c:234)
==00:00:00:21.655 21739== by 0x791844: FunctionNext (nodeFunctionscan.c:94)
==00:00:00:21.655 21739== by 0x778EC0: ExecScanFetch (execScan.c:131)
==00:00:00:21.655 21739== by 0x778F39: ExecScan (execScan.c:180)
==00:00:00:21.655 21739== by 0x791BE1: ExecFunctionScan (nodeFunctionscan.c:269)
==00:00:00:21.655 21739== by 0x774CB2: ExecProcNodeFirst (execProcnode.c:464)
==00:00:00:21.655 21739== by 0x769172: ExecProcNode.lto_priv.0 (executor.h:274)
==00:00:00:21.655 21739== by 0x76B85D: ExecutePlan (execMain.c:1649)
==00:00:00:21.655 21739== by 0x769688: standard_ExecutorRun (execMain.c:361)
==00:00:00:21.655 21739== by 0x85CD4AF: pgsp_ExecutorRun (pg_store_plans.c:1013)
==00:00:00:21.655 21739== by 0x85F03B2: pgeq_ExecutorRun (pg_ensure_queryid.c:75)
==00:00:00:21.655 21739== by 0x769574: ExecutorRun (execMain.c:305)
==00:00:00:21.655 21739== by 0xA0CA80: PortalRunSelect (pquery.c:922)
==00:00:00:21.655 21739== by 0xA0C6EA: PortalRun (pquery.c:766)
==00:00:00:21.655 21739== by 0xA05527: exec_simple_query (postgres.c:1278)
==00:00:00:21.655 21739== by 0xA0A77A: PostgresMain (postgres.c:4767)
==00:00:00:21.655 21739== by 0xA01365: BackendMain (backend_startup.c:105)
==00:00:00:21.655 21739== by 0x92D88D: postmaster_child_launch (launch_backend.c:277)
==00:00:00:21.655 21739== by 0x9339EE: BackendStartup (postmaster.c:3594)
==00:00:00:21.655 21739== by 0x930C2A: ServerLoop (postmaster.c:1676)
==00:00:00:21.655 21739== by 0x9304FB: PostmasterMain (postmaster.c:1374)
==00:00:00:21.655 21739== by 0x7F118B: main (main.c:199)
==00:00:00:21.655 21739==
==00:00:00:21.657 21739== LEAK SUMMARY:
==00:00:00:21.657 21739== definitely lost: 241 bytes in 1 blocks
==00:00:00:21.657 21739== indirectly lost: 2,283 bytes in 44 blocks
==00:00:00:21.657 21739== possibly lost: 0 bytes in 0 blocks
==00:00:00:21.657 21739== still reachable: 592,321 bytes in 1,500 blocks
==00:00:00:21.657 21739== suppressed: 305,587 bytes in 1,082 blocks
==00:00:00:21.657 21739== Reachable blocks (those to which a pointer was found) are not shown.
==00:00:00:21.657 21739== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==00:00:00:21.657 21739==
==00:00:00:21.657 21739== Use --track-origins=yes to see where uninitialised values come from
==00:00:00:21.657 21739== For lists of detected and suppressed errors, rerun with: -s
==00:00:00:21.657 21739== ERROR SUMMARY: 77 errors from 12 contexts (suppressed: 1454 from 273)
The cause can be specified as two things below.
The above case may cause continuous memory growth of the backend process.
The cases below cause the same query and plan to produce multiple result records.
There is already a fixed code for this issue.
Can I send you a Pull-Request?
I've attached the valgrind report below.
[valgrind.log]