Memory leak in BootStrapXLOG() - Mailing list pgsql-patches

From ITAGAKI Takahiro
Subject Memory leak in BootStrapXLOG()
Date
Msg-id 20050606152420.41C8.ITAGAKI.TAKAHIRO@lab.ntt.co.jp
Whole thread Raw
In response to Re: [HACKERS] WAL: O_DIRECT and multipage-writer (+ memory  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-patches
Bruce Momjian <pgman@candle.pha.pa.us> wrote:

> > BTW, I found memory leak in BootStrapXLOG(). The buffer allocated by malloc()
> > is not free()ed. ISSUE_BOOTSTRAP_MEMORYLEAK in this patch points out it.
> > (But this leak is not serious, because this function is called only once.)
>
> Does the following patch fix the memory leak you described?

Yes, the revised patch has no leak by using stack instead of malloc().
This leak is trivial, but anyway direct io needs an aligned buffer.
IMHO any of the following is ok.

[A] 1st patch
char *buffer;
void* buffer0;
buffer0 = malloc(BLCKSZ + XLOG_EXTRA_BUFFERS);
buffer = (char *) XLOG_BUFFERS_ALIGN(buffer0);
free(buffer0);

[B] 2nd patch
char *buffer;
char  buffer0[BLCKSZ + XLOG_EXTRA_BUFFERS + MAXIMUM_ALIGNOF];
buffer = XLOG_BUFFERS_ALIGN(buffer0);

[C] following code is simple if we don't care the memory leak.
char *buffer;
buffer = XLOG_BUFFERS_ALIGN( malloc(BLCKSZ + XLOG_EXTRA_BUFFERS) );


---
ITAGAKI Takahiro
NTT Cyber Space Laboratories



pgsql-patches by date:

Previous
From: Dennis Bjorklund
Date:
Subject: Re: lastval()
Next
From: Pavel Stehule
Date:
Subject: Re: SQLSTATE again