aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/tablespace.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-10-14 12:10:48 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2022-10-14 12:10:48 -0400
commit407b50f2d421bca5b134a0033176ea8f8c68dc6b (patch)
treefd62b3acfe7b3a764b386ee5d3e643644fc4fc00 /src/backend/commands/tablespace.c
parent9c911ec065df0f660e3add65d986f95928914375 (diff)
downloadpostgresql-407b50f2d421bca5b134a0033176ea8f8c68dc6b.tar.gz
postgresql-407b50f2d421bca5b134a0033176ea8f8c68dc6b.zip
Store GUC data in a memory context, instead of using malloc().
The only real argument for using malloc directly was that we needed the ability to not throw error on OOM; but mcxt.c grew that feature awhile ago. Keeping the data in a memory context improves accountability and debuggability --- for example, without this it's almost impossible to detect memory leaks in the GUC code with anything less costly than valgrind. Moreover, the next patch in this series will add a hash table for GUC lookup, and it'd be pretty silly to be using palloc-dependent hash facilities alongside malloc'd storage of the underlying data. This is a bit invasive though, in particular causing an API break for GUC check hooks that want to modify the GUC's value or use an "extra" data structure. They must now use guc_malloc() and guc_free() instead of malloc() and free(). Failure to change affected code will result in assertion failures or worse; but thanks to recent effort in the mcxt infrastructure, it shouldn't be too hard to diagnose such oversights (at least in assert-enabled builds). One note is that this changes ParseLongOption() to return short-lived palloc'd not malloc'd data. There wasn't any caller for which the previous definition was better. Discussion: https://postgr.es/m/2982579.1662416866@sss.pgh.pa.us
Diffstat (limited to 'src/backend/commands/tablespace.c')
-rw-r--r--src/backend/commands/tablespace.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index b69ff37dbbd..45b30ca566d 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -1290,8 +1290,8 @@ check_temp_tablespaces(char **newval, void **extra, GucSource source)
}
/* Now prepare an "extra" struct for assign_temp_tablespaces */
- myextra = malloc(offsetof(temp_tablespaces_extra, tblSpcs) +
- numSpcs * sizeof(Oid));
+ myextra = guc_malloc(LOG, offsetof(temp_tablespaces_extra, tblSpcs) +
+ numSpcs * sizeof(Oid));
if (!myextra)
return false;
myextra->numSpcs = numSpcs;