Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfbb2b69

Browse files
committed
Prevent memory leaks in our various bison parsers when an error occurs
during parsing. Formerly the parser's stack was allocated with mallocand so wouldn't be reclaimed; this patch makes it use palloc instead,so that flushing the current context will reclaim the memory. PerMarko Kreen.
1 parentdd6edd5 commitfbb2b69

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

‎contrib/cube/cubeparse.y

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* NdBox = [(lowerleft),(upperright)]*/
33
/* [(xLL(1)...xLL(N)),(xUR(1)...xUR(n))]*/
44

5-
/* $PostgreSQL: pgsql/contrib/cube/cubeparse.y,v 1.17 2007/02/27 23:48:05 tgl Exp $*/
5+
/* $PostgreSQL: pgsql/contrib/cube/cubeparse.y,v 1.18 2008/09/02 20:37:54 tgl Exp $*/
66

77
#defineYYPARSE_PARAM result/* need this to pass a pointer (void *) to yyparse*/
88
#defineYYSTYPEchar *
@@ -12,6 +12,17 @@
1212

1313
#include"cubedata.h"
1414

15+
/*
16+
* Bison doesn't allocate anything that needs to live across parser calls,
17+
* so we can easily have it use palloc instead of malloc. This prevents
18+
* memory leaks if we error out during parsing. Note this only works with
19+
* bison >= 2.0. However, in bison 1.875 the default is to use alloca()
20+
* if possible, so there's not really much problem anyhow, at least if
21+
* you're building with gcc.
22+
*/
23+
#defineYYMALLOC palloc
24+
#defineYYFREE pfree
25+
1526
externintcube_yylex(void);
1627

1728
staticchar *scanbuf;

‎contrib/seg/segparse.y

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
#include"utils/builtins.h"
1010
#include"segdata.h"
1111

12+
/*
13+
* Bison doesn't allocate anything that needs to live across parser calls,
14+
* so we can easily have it use palloc instead of malloc. This prevents
15+
* memory leaks if we error out during parsing. Note this only works with
16+
* bison >= 2.0. However, in bison 1.875 the default is to use alloca()
17+
* if possible, so there's not really much problem anyhow, at least if
18+
* you're building with gcc.
19+
*/
20+
#defineYYMALLOC palloc
21+
#defineYYFREE pfree
22+
1223
externintseg_yylex(void);
1324

1425
externintsignificant_digits(char *str);/* defined in seg.c*/

‎src/backend/bootstrap/bootparse.y

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.93 2008/09/01 20:42:43 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.94 2008/09/02 20:37:54 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -54,6 +54,17 @@
5454
#defineatooid(x)((Oid) strtoul((x),NULL,10))
5555

5656

57+
/*
58+
* Bison doesn't allocate anything that needs to live across parser calls,
59+
* so we can easily have it use palloc instead of malloc. This prevents
60+
* memory leaks if we error out during parsing. Note this only works with
61+
* bison >= 2.0. However, in bison 1.875 the default is to use alloca()
62+
* if possible, so there's not really much problem anyhow, at least if
63+
* you're building with gcc.
64+
*/
65+
#defineYYMALLOC palloc
66+
#defineYYFREE pfree
67+
5768
staticvoid
5869
do_start(void)
5970
{

‎src/backend/parser/gram.y

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.621 2008/09/01 20:42:44 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.622 2008/09/02 20:37:54 tgl Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -79,6 +79,17 @@
7979
*/
8080
#definebase_yylex filtered_base_yylex
8181

82+
/*
83+
* Bison doesn't allocate anything that needs to live across parser calls,
84+
* so we can easily have it use palloc instead of malloc. This prevents
85+
* memory leaks if we error out during parsing. Note this only works with
86+
* bison >= 2.0. However, in bison 1.875 the default is to use alloca()
87+
* if possible, so there's not really much problem anyhow, at least if
88+
* you're building with gcc.
89+
*/
90+
#defineYYMALLOC palloc
91+
#defineYYFREE pfree
92+
8293
extern List *parsetree;/* final parse result is delivered here*/
8394

8495
staticbool QueryIsRule =FALSE;

‎src/pl/plpgsql/src/gram.y

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.113 2008/05/15 22:39:49 tgl Exp $
12+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.114 2008/09/02 20:37:55 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -19,6 +19,18 @@
1919
#include"parser/parser.h"
2020

2121

22+
/*
23+
* Bison doesn't allocate anything that needs to live across parser calls,
24+
* so we can easily have it use palloc instead of malloc. This prevents
25+
* memory leaks if we error out during parsing. Note this only works with
26+
* bison >= 2.0. However, in bison 1.875 the default is to use alloca()
27+
* if possible, so there's not really much problem anyhow, at least if
28+
* you're building with gcc.
29+
*/
30+
#defineYYMALLOC palloc
31+
#defineYYFREE pfree
32+
33+
2234
static PLpgSQL_expr*read_sql_construct(int until,
2335
int until2,
2436
int until3,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp