Question about MemoryContexts / possible memory leak in CachedPlanSource usage

From: Daniel Migowski <dmigowski(at)ikoffice(dot)de>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Question about MemoryContexts / possible memory leak in CachedPlanSource usage
Date: 2019-07-25 20:21:06
Message-ID: 41ED3F5450C90F4D8381BC4D8DF6BBDCF02DB3E9@EXCHANGESERVER.ikoffice.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

I am just starting to get my feet wet with PostgreSQL development and am starting to understand the source, so please be kind 😊. I am working on the REL_11_4 tag.

When CachedPlanSource instances are created the field query_string is filled with pstrdup(query_string) in CreateCachedPlan, plancache.c:182, which is just a wrapper for strdup. According to the docs the returned pointer should be freed with “free” sometimes later.

I believe in DropCachedPlan the free should take place but I don’t see it. Is it just missing or is memory allocated by strdup and friends automatically created in the current MemoryContext? It so, why do I need to use palloc() instead of malloc()?

Kind regards,
Daniel Migowski

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2019-07-25 20:27:12 Re: [Proposal] Table-level Transparent Data Encryption (TDE) and Key Management Service (KMS)
Previous Message James Coleman 2019-07-25 20:14:48 [DOC] Document auto vacuum interruption