Re: [HACKERS] PATCH: Memory leaks on start-up

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Lee Kindness <lkindness(at)csl(dot)co(dot)uk>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-patches(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] PATCH: Memory leaks on start-up
Date: 2003-07-24 04:08:07
Message-ID: 200307240408.h6O487A26944@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches


Your patch has been added to the PostgreSQL unapplied patches list at:

http://momjian.postgresql.org/cgi-bin/pgpatches

I will try to apply it within the next 48 hours.

---------------------------------------------------------------------------

Lee Kindness wrote:
Content-Description: message body text

> Tom, happier with the attached patch?
>
> I'd have to disagree with regards to the memory leaks not being worth
> a mention - any such leak can cause problems when the PostgreSQL
> installation is either unattended, long-living andor has very high
> connection levels. Half a kilobyte on start-up isn't negligible in
> this light.
>
> Regards, Lee.
>
> Tom Lane writes:
> > Lee Kindness <lkindness(at)csl(dot)co(dot)uk> writes:
> > > Guys, attached is a patch to fix two memory leaks on start-up.
> >
> > I do not like the changes to miscinit.c. In the first place, it is not
> > a "memory leak" to do a one-time allocation of state for a proc_exit
> > function. A bigger complaint is that your proposed change introduces
> > fragile coupling between CreateLockFile and its callers, in order to
> > save no resources worth mentioning. More, it introduces an assumption
> > that the globals directoryLockFile and socketLockFile don't change while
> > the postmaster is running. UnlinkLockFile should unlink the file that
> > it was originally told to unlink, regardless of what happens to those
> > globals.
> >
> > If you are intent on spending code to free stuff just before the
> > postmaster exits, a better fix would be for UnlinkLockFile to free its
> > string argument after using it.
>

> Index: src/backend/libpq/pqcomm.c
> ===================================================================
> RCS file: /projects/cvsroot/pgsql-server/src/backend/libpq/pqcomm.c,v
> retrieving revision 1.157
> diff -u -r1.157 pqcomm.c
> --- src/backend/libpq/pqcomm.c 12 Jun 2003 07:36:51 -0000 1.157
> +++ src/backend/libpq/pqcomm.c 22 Jul 2003 14:16:46 -0000
> @@ -363,7 +363,7 @@
> added++;
> }
>
> - freeaddrinfo(addrs);
> + freeaddrinfo2(family, addrs);
>
> if (!added)
> {
> Index: src/backend/utils/init/miscinit.c
> ===================================================================
> RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/init/miscinit.c,v
> retrieving revision 1.104
> diff -u -r1.104 miscinit.c
> --- src/backend/utils/init/miscinit.c 27 Jun 2003 19:08:37 -0000 1.104
> +++ src/backend/utils/init/miscinit.c 22 Jul 2003 14:16:46 -0000
> @@ -673,8 +673,15 @@
> static void
> UnlinkLockFile(int status, Datum filename)
> {
> - unlink((char *) DatumGetPointer(filename));
> - /* Should we complain if the unlink fails? */
> + char *fname = (char *)DatumGetPointer(filename);
> + if( fname != NULL )
> + {
> + if( unlink(fname) != 0 )
> + {
> + /* Should we complain if the unlink fails? */
> + }
> + free(fname);
> + }
> }
>
> /*

>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2003-07-24 04:12:27 Re: this is in plain text (row level locks)
Previous Message Mike Mascari 2003-07-24 03:38:54 Re: this is in plain text (row level locks)

Browse pgsql-patches by date

  From Date Subject
Next Message Joe Conway 2003-07-24 04:11:13 patch for compile warning on date.c
Previous Message Bruce Momjian 2003-07-24 04:03:11 Re: Eliminate information_schema from oid2name listing