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

Commit84a89e2

Browse files
committed
Repair access-to-already-freed-memory error recently introduced into
VACUUM.
1 parentd261adf commit84a89e2

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

‎src/backend/commands/vacuum.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.141 2000/02/24 04:34:38 inoue Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.142 2000/03/08 23:41:00 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -144,6 +144,7 @@ PortalVariableMemory CommonSpecialPortalGetMemory(void)
144144
{
145145
returnPortalGetVariableMemory(vc_portal);
146146
}
147+
147148
boolCommonSpecialPortalIsOpen(void)
148149
{
149150
returnCommonSpecialPortalInUse;
@@ -153,6 +154,7 @@ void
153154
vacuum(char*vacrel,boolverbose,boolanalyze,List*va_spec)
154155
{
155156
NameDataVacRel;
157+
NameVacRelName;
156158
PortalVariableMemorypmem;
157159
MemoryContextold;
158160
List*le;
@@ -173,17 +175,22 @@ vacuum(char *vacrel, bool verbose, bool analyze, List *va_spec)
173175
if (IsTransactionBlock())
174176
elog(ERROR,"VACUUM cannot run inside a BEGIN/END block");
175177

176-
/* initialize vacuum cleaner, particularly vc_portal */
177-
vc_init();
178-
179178
if (verbose)
180179
MESSAGE_LEVEL=NOTICE;
181180
else
182181
MESSAGE_LEVEL=DEBUG;
183182

184-
/* vacrel gets de-allocated on transaction commit, so copy it */
183+
/* Create special portal for cross-transaction storage */
184+
CommonSpecialPortalOpen();
185+
186+
/* vacrel gets de-allocated on xact commit, so copy it to safe storage */
185187
if (vacrel)
186-
strcpy(NameStr(VacRel),vacrel);
188+
{
189+
namestrcpy(&VacRel,vacrel);
190+
VacRelName=&VacRel;
191+
}
192+
else
193+
VacRelName=NULL;
187194

188195
/* must also copy the column list, if any, to safe storage */
189196
pmem=CommonSpecialPortalGetMemory();
@@ -196,11 +203,18 @@ vacuum(char *vacrel, bool verbose, bool analyze, List *va_spec)
196203
}
197204
MemoryContextSwitchTo(old);
198205

206+
/*
207+
* Start up the vacuum cleaner.
208+
*
209+
* NOTE: since this commits the current transaction, the memory holding
210+
* any passed-in parameters gets freed here. We must have already copied
211+
* pass-by-reference parameters to safe storage. Don't make me fix this
212+
* again!
213+
*/
214+
vc_init();
215+
199216
/* vacuum the database */
200-
if (vacrel)
201-
vc_vacuum(&VacRel,analyze,va_cols);
202-
else
203-
vc_vacuum(NULL,analyze,NIL);
217+
vc_vacuum(VacRelName,analyze,va_cols);
204218

205219
/* clean up */
206220
vc_shutdown();
@@ -229,8 +243,6 @@ vacuum(char *vacrel, bool verbose, bool analyze, List *va_spec)
229243
staticvoid
230244
vc_init()
231245
{
232-
CommonSpecialPortalOpen();
233-
234246
/* matches the StartTransaction in PostgresMain() */
235247
CommitTransactionCommand();
236248
}
@@ -252,6 +264,7 @@ vc_shutdown()
252264
*/
253265
unlink(RELCACHE_INIT_FILENAME);
254266

267+
/* Clean up working storage */
255268
CommonSpecialPortalClose();
256269

257270
/* matches the CommitTransaction in PostgresMain() */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp