summaryrefslogtreecommitdiff
path: root/contrib/dblink
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2022-09-12 08:31:56 +0200
committerPeter Eisentraut <peter@eisentraut.org>2022-09-12 08:45:03 +0200
commit5015e1e1b58f81a036e4ad16291ef4b3bb7a596c (patch)
tree86ee608e961dc830e733c534db089f1e45706414 /contrib/dblink
parent2016055a92f26d648aba9f66d26cc0bcd1619eff (diff)
downloadpostgresql-5015e1e1b58f81a036e4ad16291ef4b3bb7a596c.tar.gz
Assorted examples of expanded type-safer palloc/pg_malloc API
This adds some uses of the new palloc/pg_malloc variants here and there as a demonstration and test. This is kept separate from the actual API patch, since the latter might be backpatched at some point. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/bb755632-2a43-d523-36f8-a1e7a389a907@enterprisedb.com
Diffstat (limited to 'contrib/dblink')
-rw-r--r--contrib/dblink/dblink.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index 7940387920..3df3f9bbe9 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -972,7 +972,7 @@ materializeResult(FunctionCallInfo fcinfo, PGconn *conn, PGresult *res)
rsinfo->setDesc = tupdesc;
MemoryContextSwitchTo(oldcontext);
- values = (char **) palloc(nfields * sizeof(char *));
+ values = palloc_array(char *, nfields);
/* put all tuples into the tuplestore */
for (row = 0; row < ntuples; row++)
@@ -1276,7 +1276,7 @@ storeRow(volatile storeInfo *sinfo, PGresult *res, bool first)
*/
if (sinfo->cstrs)
pfree(sinfo->cstrs);
- sinfo->cstrs = (char **) palloc(nfields * sizeof(char *));
+ sinfo->cstrs = palloc_array(char *, nfields);
}
/* Should have a single-row result if we get here */
@@ -1618,7 +1618,7 @@ dblink_get_pkey(PG_FUNCTION_ARGS)
HeapTuple tuple;
Datum result;
- values = (char **) palloc(2 * sizeof(char *));
+ values = palloc_array(char *, 2);
values[0] = psprintf("%d", call_cntr + 1);
values[1] = results[call_cntr];
@@ -2083,7 +2083,7 @@ get_pkey_attnames(Relation rel, int16 *indnkeyatts)
*indnkeyatts = index->indnkeyatts;
if (*indnkeyatts > 0)
{
- result = (char **) palloc(*indnkeyatts * sizeof(char *));
+ result = palloc_array(char *, *indnkeyatts);
for (i = 0; i < *indnkeyatts; i++)
result[i] = SPI_fname(tupdesc, index->indkey.values[i]);
@@ -2124,7 +2124,7 @@ get_text_array_contents(ArrayType *array, int *numitems)
get_typlenbyvalalign(ARR_ELEMTYPE(array),
&typlen, &typbyval, &typalign);
- values = (char **) palloc(nitems * sizeof(char *));
+ values = palloc_array(char *, nitems);
ptr = ARR_DATA_PTR(array);
bitmap = ARR_NULLBITMAP(array);
@@ -2928,7 +2928,7 @@ validate_pkattnums(Relation rel,
errmsg("number of key attributes must be > 0")));
/* Allocate output array */
- *pkattnums = (int *) palloc(pknumatts_arg * sizeof(int));
+ *pkattnums = palloc_array(int, pknumatts_arg);
*pknumatts = pknumatts_arg;
/* Validate attnums and convert to internal form */