Re: BUG #4494: Memory leak in pg_regress.c - Mailing list pgsql-bugs

From Bruce Momjian
Subject Re: BUG #4494: Memory leak in pg_regress.c
Date
Msg-id 200901082009.n08K9sQ13969@momjian.us
Whole thread Raw
In response to BUG #4494: Memory leak in pg_regress.c  ("" <dvice_null@yahoo.com>)
List pgsql-bugs
Patch written, attached, and applied.

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

dvice_null@yahoo.com wrote:
>
> The following bug has been logged online:
>
> Bug reference:      4494
> Logged by:
> Email address:      dvice_null@yahoo.com
> PostgreSQL version: Latest cvs
> Operating system:   Error in source code
> Description:        Memory leak in pg_regress.c
> Details:
>
> In file src/test/regress/pg_regress.c:1112
>
> It seems to me that variables "s" and "tmp" leak memory here if last_dot is
> false:
>
>
> static char *
> get_alternative_expectfile(const char *expectfile, int i)
> {
>         char       *last_dot;
>         int                     ssize = strlen(expectfile) + 2 + 1;
>         char       *tmp = (char *) malloc(ssize);
>         char       *s = (char *) malloc(ssize);
>
>         strcpy(tmp, expectfile);
>         last_dot = strrchr(tmp, '.');
>         if (!last_dot)
>                 return NULL;
>         *last_dot = '\0';
>         snprintf(s, ssize, "%s_%d.%s", tmp, i, last_dot + 1);
>         free(tmp);
>         return s;
> }
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
Index: src/test/regress/pg_regress.c
===================================================================
RCS file: /cvsroot/pgsql/src/test/regress/pg_regress.c,v
retrieving revision 1.56
diff -c -c -r1.56 pg_regress.c
*** src/test/regress/pg_regress.c    1 Jan 2009 17:24:04 -0000    1.56
--- src/test/regress/pg_regress.c    8 Jan 2009 20:03:29 -0000
***************
*** 1134,1140 ****
--- 1134,1144 ----
      strcpy(tmp, expectfile);
      last_dot = strrchr(tmp, '.');
      if (!last_dot)
+     {
+         free(tmp);
+         free(s);
          return NULL;
+     }
      *last_dot = '\0';
      snprintf(s, ssize, "%s_%d.%s", tmp, i, last_dot + 1);
      free(tmp);

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: PANIC: failed to re-find parent key in "100924" for split pages 1606/1673
Next
From: Simon Riggs
Date:
Subject: Re: PANIC: failed to re-find parent key in "100924" for split pages 1606/1673