Question about MemoryContexts / possible memory leak inCachedPlanSource usage - Mailing list pgsql-hackers

From Daniel Migowski
Subject Question about MemoryContexts / possible memory leak inCachedPlanSource usage
Date
Msg-id 41ED3F5450C90F4D8381BC4D8DF6BBDCF02DB3E9@EXCHANGESERVER.ikoffice.de
Whole thread Raw
Responses Re: Question about MemoryContexts / possible memory leak inCachedPlanSource usage  (Andres Freund <andres@anarazel.de>)
List 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

pgsql-hackers by date:

Previous
From: James Coleman
Date:
Subject: [DOC] Document auto vacuum interruption
Next
From: Bruce Momjian
Date:
Subject: Re: [Proposal] Table-level Transparent Data Encryption (TDE) and KeyManagement Service (KMS)