Re: Missing pfree in logical_heap_rewrite_flush_mappings() - Mailing list pgsql-hackers

From Andres Freund
Subject Re: Missing pfree in logical_heap_rewrite_flush_mappings()
Date
Msg-id 20140326172938.GD9066@alap3.anarazel.de
Whole thread Raw
In response to Re: Missing pfree in logical_heap_rewrite_flush_mappings()  (Stephen Frost <sfrost@snowman.net>)
Responses Re: Missing pfree in logical_heap_rewrite_flush_mappings()  (Stephen Frost <sfrost@snowman.net>)
List pgsql-hackers
On 2014-03-26 12:49:41 -0400, Stephen Frost wrote:
> * Ants Aasma (ants@cybertec.at) wrote:
> > It seems to me that when flushing logical mappings to disk, each
> > mapping file leaks the buffer used to pass the mappings to XLogInsert.
> > Also, it seems consistent to allocate that buffer in the RewriteState
> > memory context. Patch attached.

Good catch. There's actually no need for explicitly using the context,
we're in the appropriate one. The only other MemoryContextAlloc() caller
in there should be converted to a palloc as well.

> Hmm, yeah, it does look that way.  Why bother pfree'ing it here though
> instead of letting it be cleaned up with state->rs_cxt in
> end_heap_rewrite()?

For a somewhat large relation (say a pg_attribute in a db with lots of
tables), this can actually get to be a somewhat significant amount of
memory. It *will* currently already get cleaned up with the context, but
we can easily do better.

Greetings,

Andres Freund

-- Andres Freund                       http://www.2ndQuadrant.com/PostgreSQL Development, 24x7 Support, Training &
Services



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: small regression adjustment
Next
From: Stephen Frost
Date:
Subject: Re: Missing pfree in logical_heap_rewrite_flush_mappings()