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

Commit25ee08e

Browse files
committed
If spi.c wants to use malloc, it better test for malloc failure.
1 parent7748e9e commit25ee08e

File tree

1 file changed

+17
-7
lines changed
  • src/backend/executor

1 file changed

+17
-7
lines changed

‎src/backend/executor/spi.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* spi.c
44
*Server Programming Interface
55
*
6-
* $Id:spi.c,v 1.54 2001/05/21 14:22:17 wieck Exp $
6+
* $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.55 2001/06/01 19:43:55 tgl Exp $
77
*
88
*-------------------------------------------------------------------------
99
*/
@@ -48,8 +48,9 @@ extern void ShowUsage(void);
4848
/* =================== interface functions =================== */
4949

5050
int
51-
SPI_connect()
51+
SPI_connect(void)
5252
{
53+
_SPI_connection*new_SPI_stack;
5354

5455
/*
5556
* When procedure called by Executor _SPI_curid expected to be equal
@@ -62,19 +63,23 @@ SPI_connect()
6263
{
6364
if (_SPI_connected!=-1)
6465
elog(FATAL,"SPI_connect: no connection(s) expected");
65-
_SPI_stack= (_SPI_connection*)malloc(sizeof(_SPI_connection));
66+
new_SPI_stack= (_SPI_connection*)malloc(sizeof(_SPI_connection));
6667
}
6768
else
6869
{
6970
if (_SPI_connected <=-1)
7071
elog(FATAL,"SPI_connect: some connection(s) expected");
71-
_SPI_stack= (_SPI_connection*)realloc(_SPI_stack,
72+
new_SPI_stack= (_SPI_connection*)realloc(_SPI_stack,
7273
(_SPI_connected+2)*sizeof(_SPI_connection));
7374
}
7475

76+
if (new_SPI_stack==NULL)
77+
elog(ERROR,"Memory exhausted in SPI_connect");
78+
7579
/*
7680
* We' returning to procedure where _SPI_curid == _SPI_connected - 1
7781
*/
82+
_SPI_stack=new_SPI_stack;
7883
_SPI_connected++;
7984

8085
_SPI_current=&(_SPI_stack[_SPI_connected]);
@@ -104,7 +109,7 @@ SPI_connect()
104109
}
105110

106111
int
107-
SPI_finish()
112+
SPI_finish(void)
108113
{
109114
intres;
110115

@@ -136,8 +141,14 @@ SPI_finish()
136141
}
137142
else
138143
{
139-
_SPI_stack= (_SPI_connection*)realloc(_SPI_stack,
144+
_SPI_connection*new_SPI_stack;
145+
146+
new_SPI_stack= (_SPI_connection*)realloc(_SPI_stack,
140147
(_SPI_connected+1)*sizeof(_SPI_connection));
148+
/* This could only fail with a pretty stupid malloc package ... */
149+
if (new_SPI_stack==NULL)
150+
elog(ERROR,"Memory exhausted in SPI_finish");
151+
_SPI_stack=new_SPI_stack;
141152
_SPI_current=&(_SPI_stack[_SPI_connected]);
142153
}
143154

@@ -151,7 +162,6 @@ SPI_finish()
151162
void
152163
AtEOXact_SPI(void)
153164
{
154-
155165
/*
156166
* Note that memory contexts belonging to SPI stack entries will be
157167
* freed automatically, so we can ignore them here. We just need to

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp