aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/adt/ruleutils.c9
-rw-r--r--src/backend/utils/cache/typcache.c10
-rw-r--r--src/backend/utils/mmgr/mcxt.c20
3 files changed, 24 insertions, 15 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 70d723e80ca..c5a49d0be34 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -4855,14 +4855,9 @@ expand_colnames_array_to(deparse_columns *colinfo, int n)
if (n > colinfo->num_cols)
{
if (colinfo->colnames == NULL)
- colinfo->colnames = (char **) palloc0(n * sizeof(char *));
+ colinfo->colnames = palloc0_array(char *, n);
else
- {
- colinfo->colnames = (char **) repalloc(colinfo->colnames,
- n * sizeof(char *));
- memset(colinfo->colnames + colinfo->num_cols, 0,
- (n - colinfo->num_cols) * sizeof(char *));
- }
+ colinfo->colnames = repalloc0_array(colinfo->colnames, char *, colinfo->num_cols, n);
colinfo->num_cols = n;
}
}
diff --git a/src/backend/utils/cache/typcache.c b/src/backend/utils/cache/typcache.c
index 808f9ebd0d2..b69366fa29d 100644
--- a/src/backend/utils/cache/typcache.c
+++ b/src/backend/utils/cache/typcache.c
@@ -1714,14 +1714,8 @@ ensure_record_cache_typmod_slot_exists(int32 typmod)
{
int32 newlen = pg_nextpower2_32(typmod + 1);
- RecordCacheArray = (TupleDesc *) repalloc(RecordCacheArray,
- newlen * sizeof(TupleDesc));
- memset(RecordCacheArray + RecordCacheArrayLen, 0,
- (newlen - RecordCacheArrayLen) * sizeof(TupleDesc));
- RecordIdentifierArray = (uint64 *) repalloc(RecordIdentifierArray,
- newlen * sizeof(uint64));
- memset(RecordIdentifierArray + RecordCacheArrayLen, 0,
- (newlen - RecordCacheArrayLen) * sizeof(uint64));
+ RecordCacheArray = repalloc0_array(RecordCacheArray, TupleDesc, RecordCacheArrayLen, newlen);
+ RecordIdentifierArray = repalloc0_array(RecordIdentifierArray, uint64, RecordCacheArrayLen, newlen);
RecordCacheArrayLen = newlen;
}
}
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index f526ca82c15..57bd6690ca0 100644
--- a/src/backend/utils/mmgr/mcxt.c
+++ b/src/backend/utils/mmgr/mcxt.c
@@ -1396,6 +1396,26 @@ repalloc_extended(void *pointer, Size size, int flags)
}
/*
+ * repalloc0
+ * Adjust the size of a previously allocated chunk and zero out the added
+ * space.
+ */
+void *
+repalloc0(void *pointer, Size oldsize, Size size)
+{
+ void *ret;
+
+ /* catch wrong argument order */
+ if (unlikely(oldsize > size))
+ elog(ERROR, "invalid repalloc0 call: oldsize %zu, new size %zu",
+ oldsize, size);
+
+ ret = repalloc(pointer, size);
+ memset((char *) ret + oldsize, 0, (size - oldsize));
+ return ret;
+}
+
+/*
* MemoryContextAllocHuge
* Allocate (possibly-expansive) space within the specified context.
*