Memory leak in BootStrapXLOG()

From: ITAGAKI Takahiro <itagaki(dot)takahiro(at)lab(dot)ntt(dot)co(dot)jp>
To: pgsql-patches(at)postgresql(dot)org
Subject: Memory leak in BootStrapXLOG()
Date: 2005-06-06 06:53:27
Message-ID: 20050606152420.41C8.ITAGAKI.TAKAHIRO@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Himanshu Baweja 2005-06-06 07:53:51 Re: pg_stats not getting updated....
Previous Message Nithin Sontineni 2005-06-06 06:24:06 need help

Browse pgsql-patches by date

  From Date Subject
Next Message Pavel Stehule 2005-06-06 08:36:57 Re: SQLSTATE again
Previous Message Dennis Bjorklund 2005-06-06 06:02:01 Re: lastval()