Re: Memory leaks in BufFileOpenShared() - Mailing list pgsql-hackers

From Antonin Houska
Subject Re: Memory leaks in BufFileOpenShared()
Date
Msg-id 16139.1529049566@localhost
Whole thread Raw
In response to Re: Memory leaks in BufFileOpenShared()  (Tatsuo Ishii <ishii@sraoss.co.jp>)
Responses Re: Memory leaks in BufFileOpenShared()
List pgsql-hackers
Now I see that BufFileCreateShared() has similar problem with file->name.

More generic problem I see is that the common initialization of BufFile is
repeated a few times. The attached patch tries to improve that (it also fixes
the duplicate allocation of file->name).

Tatsuo Ishii <ishii@sraoss.co.jp> wrote:

> > Memory is allocated twice for "file" and "files" variables. Possible fix:
> >
> > diff --git a/src/backend/storage/file/buffile.c b/src/backend/storage/file/buffile.c
> > index d8a18dd3dc..00f61748b3 100644
> > --- a/src/backend/storage/file/buffile.c
> > +++ b/src/backend/storage/file/buffile.c
> > @@ -277,10 +277,10 @@ BufFileCreateShared(SharedFileSet *fileset, const char *name)
> >  BufFile *
> >  BufFileOpenShared(SharedFileSet *fileset, const char *name)
> >  {
> > -       BufFile    *file = (BufFile *) palloc(sizeof(BufFile));
> > +       BufFile    *file;
> >         char            segment_name[MAXPGPATH];
> >         Size            capacity = 16;
> > -       File       *files = palloc(sizeof(File) * capacity);
> > +       File       *files;
> >         int                     nfiles = 0;
> >
> >         file = (BufFile *) palloc(sizeof(BufFile));
>
> Good catch. Thanks.
>
> Best regards,
> --
> Tatsuo Ishii
> SRA OSS, Inc. Japan
> English: http://www.sraoss.co.jp/index_en.php
> Japanese:http://www.sraoss.co.jp
>

--
Antonin Houska
Cybertec Schönig & Schönig GmbH
Gröhrmühlgasse 26, A-2700 Wiener Neustadt
Web: https://www.cybertec-postgresql.com


Attachment

pgsql-hackers by date:

Previous
From: Raphael Medaer
Date:
Subject: Re: Attempt to fix inheritance limitations: unique and foreign keyconstraints
Next
From: Tatsuo Ishii
Date:
Subject: Re: Memory leaks in BufFileOpenShared()