Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4b9d84d

Browse files
committed
Fix memory leak in tokenize_file, per report from Vadim Passynkov.
1 parent f6d2783 commit 4b9d84d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/backend/libpq/hba.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.129 2004/08/29 05:06:43 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.130 2004/09/18 01:22:58 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -213,6 +213,9 @@ next_token(FILE *fp, char *buf, int bufsz)
213213
* Tokenize file and handle file inclusion and comma lists. We have
214214
* to break apart the commas to expand any file names then
215215
* reconstruct with commas.
216+
*
217+
* The result is always a palloc'd string. If it's zero-length then
218+
* we have reached EOL.
216219
*/
217220
static char *
218221
next_token_expand(FILE *file)
@@ -225,7 +228,7 @@ next_token_expand(FILE *file)
225228
do
226229
{
227230
next_token(file, buf, sizeof(buf));
228-
if (!*buf)
231+
if (!buf[0])
229232
break;
230233

231234
if (buf[strlen(buf) - 1] == ',')
@@ -382,7 +385,7 @@ tokenize_file(FILE *file, List **lines, List **line_nums)
382385
buf = next_token_expand(file);
383386

384387
/* add token to list, unless we are at EOL or comment start */
385-
if (buf[0] != '\0')
388+
if (buf[0])
386389
{
387390
if (current_line == NIL)
388391
{
@@ -403,6 +406,8 @@ tokenize_file(FILE *file, List **lines, List **line_nums)
403406
current_line = NIL;
404407
/* Advance line number whenever we reach EOL */
405408
line_number++;
409+
/* Don't forget to pfree the next_token_expand result */
410+
pfree(buf);
406411
}
407412
}
408413
}

0 commit comments

Comments
 (0)