Skip to content

Commit 84a89e2

Browse files
committed
Repair access-to-already-freed-memory error recently introduced into
VACUUM.
1 parent d261adf commit 84a89e2

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
return PortalGetVariableMemory(vc_portal);
146146
}
147+
147148
bool CommonSpecialPortalIsOpen(void)
148149
{
149150
return CommonSpecialPortalInUse;
@@ -153,6 +154,7 @@ void
153154
vacuum(char *vacrel, bool verbose, bool analyze, List *va_spec)
154155
{
155156
NameData VacRel;
157+
Name VacRelName;
156158
PortalVariableMemory pmem;
157159
MemoryContext old;
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
static void
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy