Skip to content

Commit 814c8a0

Browse files
committed
Further fixes for per-tablespace options patch.
Add missing varlena header to TableSpaceOpts structure. And, per Tom Lane, instead of calling tablespace_reloptions in CacheMemoryContext, call it in the caller's memory context and copy the value over afterwards, to reduce the chances of a session-lifetime memory leak.
1 parent c7f0891 commit 814c8a0

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/backend/utils/cache/spccache.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/backend/utils/cache/spccache.c,v 1.3 2010/01/06 23:00:02 tgl Exp $
15+
* $PostgreSQL: pgsql/src/backend/utils/cache/spccache.c,v 1.4 2010/01/07 03:53:08 rhaas Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -142,7 +142,6 @@ get_tablespace(Oid spcid)
142142
{
143143
Datum datum;
144144
bool isNull;
145-
MemoryContext octx;
146145

147146
datum = SysCacheGetAttr(TABLESPACEOID,
148147
tp,
@@ -152,10 +151,9 @@ get_tablespace(Oid spcid)
152151
opts = NULL;
153152
else
154153
{
155-
/* XXX should NOT do the parsing work in CacheMemoryContext */
156-
octx = MemoryContextSwitchTo(CacheMemoryContext);
157-
opts = (TableSpaceOpts *) tablespace_reloptions(datum, false);
158-
MemoryContextSwitchTo(octx);
154+
bytea *bytea_opts = tablespace_reloptions(datum, false);
155+
opts = MemoryContextAlloc(CacheMemoryContext, VARSIZE(bytea_opts));
156+
memcpy(opts, bytea_opts, VARSIZE(bytea_opts));
159157
}
160158
ReleaseSysCache(tp);
161159
}

src/include/commands/tablespace.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/commands/tablespace.h,v 1.22 2010/01/05 21:53:59 rhaas Exp $
10+
* $PostgreSQL: pgsql/src/include/commands/tablespace.h,v 1.23 2010/01/07 03:53:08 rhaas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -34,6 +34,7 @@ typedef struct xl_tblspc_drop_rec
3434

3535
typedef struct TableSpaceOpts
3636
{
37+
int32 vl_len_; /* varlena header (do not touch directly!) */
3738
float8 random_page_cost;
3839
float8 seq_page_cost;
3940
} TableSpaceOpts;

0 commit comments

Comments
 (0)