summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian2002-11-11 03:02:20 +0000
committerBruce Momjian2002-11-11 03:02:20 +0000
commit07e0bd589016db0479e1a92d6b387d4e5a874829 (patch)
tree2170da5effbf501a9210beb34e70f09de5c72238
parentd1b13b365bb16f1f124d86ec9b70d653a91f95cc (diff)
Back out use of palloc0 in place if palloc/MemSet. Seems constant len
to MemSet is a performance boost.
-rw-r--r--contrib/dblink/dblink.c3
-rw-r--r--contrib/intarray/_int.c4
-rw-r--r--src/backend/access/common/indextuple.c3
-rw-r--r--src/backend/access/common/tupdesc.c3
-rw-r--r--src/backend/access/gist/gist.c6
-rw-r--r--src/backend/access/nbtree/nbtsort.c8
-rw-r--r--src/backend/access/rtree/rtproc.c8
-rw-r--r--src/backend/catalog/index.c3
-rw-r--r--src/backend/commands/analyze.c3
-rw-r--r--src/backend/commands/copy.c3
-rw-r--r--src/backend/commands/explain.c3
-rw-r--r--src/backend/commands/opclasscmds.c9
-rw-r--r--src/backend/commands/prepare.c3
-rw-r--r--src/backend/commands/trigger.c27
-rw-r--r--src/backend/commands/vacuumlazy.c3
-rw-r--r--src/backend/executor/execMain.c13
-rw-r--r--src/backend/executor/functions.c7
-rw-r--r--src/backend/executor/nodeAgg.c18
-rw-r--r--src/backend/executor/nodeAppend.c3
-rw-r--r--src/backend/executor/nodeSort.c6
-rw-r--r--src/backend/executor/spi.c7
-rw-r--r--src/backend/optimizer/path/allpaths.c3
-rw-r--r--src/backend/parser/parse_func.c3
-rw-r--r--src/backend/parser/parse_node.c3
-rw-r--r--src/backend/postmaster/postmaster.c4
-rw-r--r--src/backend/utils/adt/acl.c3
-rw-r--r--src/backend/utils/adt/arrayfuncs.c17
-rw-r--r--src/backend/utils/adt/geo_ops.c7
-rw-r--r--src/backend/utils/adt/network.c12
-rw-r--r--src/backend/utils/adt/varbit.c9
-rw-r--r--src/backend/utils/cache/catcache.c3
-rw-r--r--src/backend/utils/cache/relcache.c15
-rw-r--r--src/backend/utils/fmgr/fmgr.c3
-rw-r--r--src/backend/utils/sort/tuplesort.c10
-rw-r--r--src/backend/utils/sort/tuplestore.c4
-rw-r--r--src/include/c.h3
-rw-r--r--src/pl/plpgsql/src/pl_exec.c5
-rw-r--r--src/test/regress/regress.c3
38 files changed, 176 insertions, 74 deletions
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index 8cbce09d1b..67a9d30d64 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -1442,7 +1442,8 @@ init_dblink_results(MemoryContext fn_mcxt)
oldcontext = MemoryContextSwitchTo(fn_mcxt);
- retval = (dblink_results *) palloc0(sizeof(dblink_results));
+ retval = (dblink_results *) palloc(sizeof(dblink_results));
+ MemSet(retval, 0, sizeof(dblink_results));
retval->tup_num = -1;
retval->res_id_index = -1;
diff --git a/contrib/intarray/_int.c b/contrib/intarray/_int.c
index 325d504d84..dc674e09ff 100644
--- a/contrib/intarray/_int.c
+++ b/contrib/intarray/_int.c
@@ -916,8 +916,10 @@ new_intArrayType(int num)
ArrayType *r;
int nbytes = ARR_OVERHEAD(NDIM) + sizeof(int) * num;
- r = (ArrayType *) palloc0(nbytes);
+ r = (ArrayType *) palloc(nbytes);
+ MemSet(r, 0, nbytes);
+
ARR_SIZE(r) = nbytes;
ARR_NDIM(r) = NDIM;
ARR_ELEMTYPE(r) = INT4OID;
diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/common/indextuple.c
index e9d58c09d8..3f548947b1 100644
--- a/src/backend/access/common/indextuple.c
+++ b/src/backend/access/common/indextuple.c
@@ -121,8 +121,9 @@ index_formtuple(TupleDesc tupleDescriptor,
#endif
size = MAXALIGN(size); /* be conservative */
- tp = (char *) palloc0(size);
+ tp = (char *) palloc(size);
tuple = (IndexTuple) tp;
+ MemSet(tp, 0, size);
DataFill((char *) tp + hoff,
tupleDescriptor,
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index 64c4dd8592..1788042353 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -60,7 +60,8 @@ CreateTemplateTupleDesc(int natts, bool hasoid)
{
uint32 size = natts * sizeof(Form_pg_attribute);
- desc->attrs = (Form_pg_attribute *) palloc0(size);
+ desc->attrs = (Form_pg_attribute *) palloc(size);
+ MemSet(desc->attrs, 0, size);
}
else
desc->attrs = NULL;
diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index 513cc05bd5..16c393d230 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -1316,8 +1316,10 @@ gistSplit(Relation r,
*/
if (r->rd_att->natts > 1)
{
- v.spl_idgrp = (int *) palloc0(sizeof(int) * (*len + 1));
- v.spl_grpflag = (char *) palloc0(sizeof(char) * (*len + 1));
+ v.spl_idgrp = (int *) palloc(sizeof(int) * (*len + 1));
+ MemSet((void *) v.spl_idgrp, 0, sizeof(int) * (*len + 1));
+ v.spl_grpflag = (char *) palloc(sizeof(char) * (*len + 1));
+ MemSet((void *) v.spl_grpflag, 0, sizeof(char) * (*len + 1));
v.spl_ngrp = (int *) palloc(sizeof(int) * (*len + 1));
MaxGrpId = gistfindgroup(giststate, (GISTENTRY *) VARDATA(entryvec), &v);
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index be5485f9d8..b5e29abab4 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -111,7 +111,9 @@ static void _bt_load(Relation index, BTSpool *btspool, BTSpool *btspool2);
BTSpool *
_bt_spoolinit(Relation index, bool isunique)
{
- BTSpool *btspool = (BTSpool *) palloc0(sizeof(BTSpool));
+ BTSpool *btspool = (BTSpool *) palloc(sizeof(BTSpool));
+
+ MemSet((char *) btspool, 0, sizeof(BTSpool));
btspool->index = index;
btspool->isunique = isunique;
@@ -205,7 +207,9 @@ _bt_blnewpage(Relation index, Buffer *buf, Page *page, int flags)
static BTPageState *
_bt_pagestate(Relation index, int flags, int level)
{
- BTPageState *state = (BTPageState *) palloc0(sizeof(BTPageState));
+ BTPageState *state = (BTPageState *) palloc(sizeof(BTPageState));
+
+ MemSet((char *) state, 0, sizeof(BTPageState));
/* create initial page */
_bt_blnewpage(index, &(state->btps_buf), &(state->btps_page), flags);
diff --git a/src/backend/access/rtree/rtproc.c b/src/backend/access/rtree/rtproc.c
index e6ae2762e7..b94ee9cdff 100644
--- a/src/backend/access/rtree/rtproc.c
+++ b/src/backend/access/rtree/rtproc.c
@@ -103,7 +103,9 @@ rt_poly_union(PG_FUNCTION_ARGS)
POLYGON *b = PG_GETARG_POLYGON_P(1);
POLYGON *p;
- p = (POLYGON *) palloc0(sizeof(POLYGON)); /* zero any holes */
+ p = (POLYGON *) palloc(sizeof(POLYGON));
+
+ MemSet((char *) p, 0, sizeof(POLYGON)); /* zero any holes */
p->size = sizeof(POLYGON);
p->npts = 0;
p->boundbox.high.x = Max(a->boundbox.high.x, b->boundbox.high.x);
@@ -125,7 +127,9 @@ rt_poly_inter(PG_FUNCTION_ARGS)
POLYGON *b = PG_GETARG_POLYGON_P(1);
POLYGON *p;
- p = (POLYGON *) palloc0(sizeof(POLYGON)); /* zero any holes */
+ p = (POLYGON *) palloc(sizeof(POLYGON));
+
+ MemSet((char *) p, 0, sizeof(POLYGON)); /* zero any holes */
p->size = sizeof(POLYGON);
p->npts = 0;
p->boundbox.high.x = Min(a->boundbox.high.x, b->boundbox.high.x);
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 15d0ec7584..be05d894d4 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -112,7 +112,8 @@ BuildFuncTupleDesc(Oid funcOid,
* Allocate and zero a tuple descriptor for a one-column tuple.
*/
funcTupDesc = CreateTemplateTupleDesc(1, false);
- funcTupDesc->attrs[0] = (Form_pg_attribute) palloc0(ATTRIBUTE_TUPLE_SIZE);
+ funcTupDesc->attrs[0] = (Form_pg_attribute) palloc(ATTRIBUTE_TUPLE_SIZE);
+ MemSet(funcTupDesc->attrs[0], 0, ATTRIBUTE_TUPLE_SIZE);
/*
* Lookup the function to get its name and return type.
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index b8446ac1d2..578dc2c62b 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -423,7 +423,8 @@ examine_attribute(Relation onerel, int attnum)
* If we have "=" then we're at least able to do the minimal
* algorithm, so start filling in a VacAttrStats struct.
*/
- stats = (VacAttrStats *) palloc0(sizeof(VacAttrStats));
+ stats = (VacAttrStats *) palloc(sizeof(VacAttrStats));
+ MemSet(stats, 0, sizeof(VacAttrStats));
stats->attnum = attnum;
stats->attr = (Form_pg_attribute) palloc(ATTRIBUTE_TUPLE_SIZE);
memcpy(stats->attr, attr, ATTRIBUTE_TUPLE_SIZE);
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 0b86401004..ba72dbf839 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -804,8 +804,9 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
elements = (Oid *) palloc(num_phys_attrs * sizeof(Oid));
defmap = (int *) palloc(num_phys_attrs * sizeof(int));
defexprs = (Node **) palloc(num_phys_attrs * sizeof(Node *));
- constraintexprs = (Node **) palloc0(num_phys_attrs * sizeof(Node *));
+ constraintexprs = (Node **) palloc(num_phys_attrs * sizeof(Node *));
constraintconsts = (Const **) palloc(num_phys_attrs * sizeof(Const *));
+ MemSet(constraintexprs, 0, num_phys_attrs * sizeof(Node *));
for (i = 0; i < num_phys_attrs; i++)
{
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index eefc506bef..7004f691be 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -164,7 +164,8 @@ ExplainOneQuery(Query *query, ExplainStmt *stmt, TupOutputState *tstate)
(double) endtime.tv_usec / 1000000.0;
}
- es = (ExplainState *) palloc0(sizeof(ExplainState));
+ es = (ExplainState *) palloc(sizeof(ExplainState));
+ MemSet(es, 0, sizeof(ExplainState));
es->printCost = true; /* default */
diff --git a/src/backend/commands/opclasscmds.c b/src/backend/commands/opclasscmds.c
index c78dde0214..222e88eb2e 100644
--- a/src/backend/commands/opclasscmds.c
+++ b/src/backend/commands/opclasscmds.c
@@ -124,9 +124,12 @@ DefineOpClass(CreateOpClassStmt *stmt)
* do this mainly so that we can detect duplicate strategy numbers and
* support-proc numbers.
*/
- operators = (Oid *) palloc0(sizeof(Oid) * numOperators);
- procedures = (Oid *) palloc0(sizeof(Oid) * numProcs);
- recheck = (bool *) palloc0(sizeof(bool) * numOperators);
+ operators = (Oid *) palloc(sizeof(Oid) * numOperators);
+ MemSet(operators, 0, sizeof(Oid) * numOperators);
+ procedures = (Oid *) palloc(sizeof(Oid) * numProcs);
+ MemSet(procedures, 0, sizeof(Oid) * numProcs);
+ recheck = (bool *) palloc(sizeof(bool) * numOperators);
+ MemSet(recheck, 0, sizeof(bool) * numOperators);
/*
* Scan the "items" list to obtain additional info.
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c
index 798ad6510c..1f92b2ef86 100644
--- a/src/backend/commands/prepare.c
+++ b/src/backend/commands/prepare.c
@@ -116,7 +116,8 @@ ExecuteQuery(ExecuteStmt *stmt, CommandDest outputDest)
if (nargs != length(stmt->params))
elog(ERROR, "ExecuteQuery: wrong number of arguments");
- paramLI = (ParamListInfo) palloc0((nargs + 1) * sizeof(ParamListInfoData));
+ paramLI = (ParamListInfo) palloc((nargs + 1) * sizeof(ParamListInfoData));
+ MemSet(paramLI, 0, (nargs + 1) * sizeof(ParamListInfoData));
foreach(l, stmt->params)
{
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index e043d2752f..81570df8d1 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -94,7 +94,7 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
constrrelid = RangeVarGetRelid(stmt->constrrel, false);
else if (stmt->isconstraint)
{
- /*
+ /*
* If this trigger is a constraint (and a foreign key one)
* then we really need a constrrelid. Since we don't have one,
* we'll try to generate one from the argument information.
@@ -779,7 +779,8 @@ RelationBuildTriggers(Relation relation)
RelationGetRelationName(relation));
/* Build trigdesc */
- trigdesc = (TriggerDesc *) palloc0(sizeof(TriggerDesc));
+ trigdesc = (TriggerDesc *) palloc(sizeof(TriggerDesc));
+ MemSet(trigdesc, 0, sizeof(TriggerDesc));
trigdesc->triggers = triggers;
trigdesc->numtriggers = ntrigs;
for (found = 0; found < ntrigs; found++)
@@ -1145,8 +1146,12 @@ ExecBRInsertTriggers(EState *estate, ResultRelInfo *relinfo,
/* Allocate cache space for fmgr lookup info, if not done yet */
if (relinfo->ri_TrigFunctions == NULL)
+ {
relinfo->ri_TrigFunctions = (FmgrInfo *)
- palloc0(trigdesc->numtriggers * sizeof(FmgrInfo));
+ palloc(trigdesc->numtriggers * sizeof(FmgrInfo));
+ MemSet(relinfo->ri_TrigFunctions, 0,
+ trigdesc->numtriggers * sizeof(FmgrInfo));
+ }
LocTriggerData.type = T_TriggerData;
LocTriggerData.tg_event = TRIGGER_EVENT_INSERT | TRIGGER_EVENT_ROW | TRIGGER_EVENT_BEFORE;
@@ -1201,8 +1206,12 @@ ExecBRDeleteTriggers(EState *estate, ResultRelInfo *relinfo,
/* Allocate cache space for fmgr lookup info, if not done yet */
if (relinfo->ri_TrigFunctions == NULL)
+ {
relinfo->ri_TrigFunctions = (FmgrInfo *)
- palloc0(trigdesc->numtriggers * sizeof(FmgrInfo));
+ palloc(trigdesc->numtriggers * sizeof(FmgrInfo));
+ MemSet(relinfo->ri_TrigFunctions, 0,
+ trigdesc->numtriggers * sizeof(FmgrInfo));
+ }
LocTriggerData.type = T_TriggerData;
LocTriggerData.tg_event = TRIGGER_EVENT_DELETE | TRIGGER_EVENT_ROW | TRIGGER_EVENT_BEFORE;
@@ -1273,8 +1282,12 @@ ExecBRUpdateTriggers(EState *estate, ResultRelInfo *relinfo,
/* Allocate cache space for fmgr lookup info, if not done yet */
if (relinfo->ri_TrigFunctions == NULL)
+ {
relinfo->ri_TrigFunctions = (FmgrInfo *)
- palloc0(trigdesc->numtriggers * sizeof(FmgrInfo));
+ palloc(trigdesc->numtriggers * sizeof(FmgrInfo));
+ MemSet(relinfo->ri_TrigFunctions, 0,
+ trigdesc->numtriggers * sizeof(FmgrInfo));
+ }
LocTriggerData.type = T_TriggerData;
LocTriggerData.tg_event = TRIGGER_EVENT_UPDATE | TRIGGER_EVENT_ROW | TRIGGER_EVENT_BEFORE;
@@ -1756,7 +1769,9 @@ deferredTriggerInvokeEvents(bool immediate_only)
* Allocate space to cache fmgr lookup info for triggers.
*/
finfo = (FmgrInfo *)
- palloc0(trigdesc->numtriggers * sizeof(FmgrInfo));
+ palloc(trigdesc->numtriggers * sizeof(FmgrInfo));
+ MemSet(finfo, 0,
+ trigdesc->numtriggers * sizeof(FmgrInfo));
}
DeferredTriggerExecute(event, i, rel, trigdesc, finfo,
diff --git a/src/backend/commands/vacuumlazy.c b/src/backend/commands/vacuumlazy.c
index bd83824bc5..d5364247d3 100644
--- a/src/backend/commands/vacuumlazy.c
+++ b/src/backend/commands/vacuumlazy.c
@@ -147,7 +147,8 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
vacuum_set_xid_limits(vacstmt, onerel->rd_rel->relisshared,
&OldestXmin, &FreezeLimit);
- vacrelstats = (LVRelStats *) palloc0(sizeof(LVRelStats));
+ vacrelstats = (LVRelStats *) palloc(sizeof(LVRelStats));
+ MemSet(vacrelstats, 0, sizeof(LVRelStats));
/* Open all indexes of the relation */
vac_open_indexes(onerel, &nindexes, &Irel);
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index b5cf69ff74..6ce3ccd4b3 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -106,8 +106,12 @@ ExecutorStart(QueryDesc *queryDesc, EState *estate)
Assert(queryDesc != NULL);
if (queryDesc->plantree->nParamExec > 0)
+ {
estate->es_param_exec_vals = (ParamExecData *)
- palloc0(queryDesc->plantree->nParamExec * sizeof(ParamExecData));
+ palloc(queryDesc->plantree->nParamExec * sizeof(ParamExecData));
+ MemSet(estate->es_param_exec_vals, 0,
+ queryDesc->plantree->nParamExec * sizeof(ParamExecData));
+ }
/*
* Make our own private copy of the current query snapshot data.
@@ -1788,12 +1792,17 @@ EvalPlanQual(EState *estate, Index rti, ItemPointer tid)
*/
epqstate->es_evTupleNull = (bool *) palloc(rtsize * sizeof(bool));
if (epq == NULL)
+ {
/* first PQ stack entry */
epqstate->es_evTuple = (HeapTuple *)
- palloc0(rtsize * sizeof(HeapTuple));
+ palloc(rtsize * sizeof(HeapTuple));
+ memset(epqstate->es_evTuple, 0, rtsize * sizeof(HeapTuple));
+ }
else
+ {
/* later stack entries share the same storage */
epqstate->es_evTuple = epq->estate.es_evTuple;
+ }
}
else
{
diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c
index cea920ba51..06a1f36571 100644
--- a/src/backend/executor/functions.c
+++ b/src/backend/executor/functions.c
@@ -121,7 +121,9 @@ init_execution_state(char *src, Oid *argOidVect, int nargs)
int i;
ParamListInfo paramLI;
- paramLI = (ParamListInfo) palloc0((nargs + 1) * sizeof(ParamListInfoData));
+ paramLI = (ParamListInfo) palloc((nargs + 1) * sizeof(ParamListInfoData));
+
+ MemSet(paramLI, 0, (nargs + 1) * sizeof(ParamListInfoData));
estate->es_param_list_info = paramLI;
@@ -183,7 +185,8 @@ init_sql_fcache(FmgrInfo *finfo)
typeStruct = (Form_pg_type) GETSTRUCT(typeTuple);
- fcache = (SQLFunctionCachePtr) palloc0(sizeof(SQLFunctionCache));
+ fcache = (SQLFunctionCachePtr) palloc(sizeof(SQLFunctionCache));
+ MemSet(fcache, 0, sizeof(SQLFunctionCache));
/*
* get the type length and by-value flag from the type tuple
diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c
index e1c2452f90..e5d515e18f 100644
--- a/src/backend/executor/nodeAgg.c
+++ b/src/backend/executor/nodeAgg.c
@@ -651,7 +651,8 @@ lookup_hash_entry(Agg *node, TupleTableSlot *slot)
MemoryContextSwitchTo(aggstate->aggcontext);
entrysize = sizeof(AggHashEntryData) +
(aggstate->numaggs - 1) * sizeof(AggStatePerGroupData);
- entry = (AggHashEntry) palloc0(entrysize);
+ entry = (AggHashEntry) palloc(entrysize);
+ MemSet(entry, 0, entrysize);
entry->hashkey = hashkey;
entry->firstTuple = heap_copytuple(tuple);
@@ -887,8 +888,9 @@ agg_retrieve_direct(Agg *node)
Datum *dvalues;
char *dnulls;
- dvalues = (Datum *) palloc0(sizeof(Datum) * tupType->natts);
+ dvalues = (Datum *) palloc(sizeof(Datum) * tupType->natts);
dnulls = (char *) palloc(sizeof(char) * tupType->natts);
+ MemSet(dvalues, 0, sizeof(Datum) * tupType->natts);
MemSet(dnulls, 'n', sizeof(char) * tupType->natts);
nullsTuple = heap_formtuple(tupType, dvalues, dnulls);
ExecStoreTuple(nullsTuple,
@@ -1168,10 +1170,13 @@ ExecInitAgg(Agg *node, EState *estate, Plan *parent)
* allocate my private per-agg working storage
*/
econtext = aggstate->csstate.cstate.cs_ExprContext;
- econtext->ecxt_aggvalues = (Datum *) palloc0(sizeof(Datum) * numaggs);
- econtext->ecxt_aggnulls = (bool *) palloc0(sizeof(bool) * numaggs);
+ econtext->ecxt_aggvalues = (Datum *) palloc(sizeof(Datum) * numaggs);
+ MemSet(econtext->ecxt_aggvalues, 0, sizeof(Datum) * numaggs);
+ econtext->ecxt_aggnulls = (bool *) palloc(sizeof(bool) * numaggs);
+ MemSet(econtext->ecxt_aggnulls, 0, sizeof(bool) * numaggs);
- peragg = (AggStatePerAgg) palloc0(sizeof(AggStatePerAggData) * numaggs);
+ peragg = (AggStatePerAgg) palloc(sizeof(AggStatePerAggData) * numaggs);
+ MemSet(peragg, 0, sizeof(AggStatePerAggData) * numaggs);
aggstate->peragg = peragg;
if (node->aggstrategy == AGG_HASHED)
@@ -1183,7 +1188,8 @@ ExecInitAgg(Agg *node, EState *estate, Plan *parent)
{
AggStatePerGroup pergroup;
- pergroup = (AggStatePerGroup) palloc0(sizeof(AggStatePerGroupData) * numaggs);
+ pergroup = (AggStatePerGroup) palloc(sizeof(AggStatePerGroupData) * numaggs);
+ MemSet(pergroup, 0, sizeof(AggStatePerGroupData) * numaggs);
aggstate->pergroup = pergroup;
}
diff --git a/src/backend/executor/nodeAppend.c b/src/backend/executor/nodeAppend.c
index 2f259c8c4e..0d2fa9dcda 100644
--- a/src/backend/executor/nodeAppend.c
+++ b/src/backend/executor/nodeAppend.c
@@ -166,7 +166,8 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
appendplans = node->appendplans;
nplans = length(appendplans);
- initialized = (bool *) palloc0(nplans * sizeof(bool));
+ initialized = (bool *) palloc(nplans * sizeof(bool));
+ MemSet(initialized, 0, nplans * sizeof(bool));
/*
* create new AppendState for our append node
diff --git a/src/backend/executor/nodeSort.c b/src/backend/executor/nodeSort.c
index cfa6235dde..2b713cf228 100644
--- a/src/backend/executor/nodeSort.c
+++ b/src/backend/executor/nodeSort.c
@@ -50,9 +50,11 @@ ExtractSortKeys(Sort *sortnode,
*/
if (keycount <= 0)
elog(ERROR, "ExtractSortKeys: keycount <= 0");
- sortOps = (Oid *) palloc0(keycount * sizeof(Oid));
+ sortOps = (Oid *) palloc(keycount * sizeof(Oid));
+ MemSet(sortOps, 0, keycount * sizeof(Oid));
*sortOperators = sortOps;
- attNos = (AttrNumber *) palloc0(keycount * sizeof(AttrNumber));
+ attNos = (AttrNumber *) palloc(keycount * sizeof(AttrNumber));
+ MemSet(attNos, 0, keycount * sizeof(AttrNumber));
*attNums = attNos;
/*
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index 10c6175ef3..8e8f1c0b28 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -783,8 +783,9 @@ SPI_cursor_open(char *name, void *plan, Datum *Values, char *Nulls)
{
ParamListInfo paramLI;
- paramLI = (ParamListInfo) palloc0((spiplan->nargs + 1) *
+ paramLI = (ParamListInfo) palloc((spiplan->nargs + 1) *
sizeof(ParamListInfoData));
+ MemSet(paramLI, 0, (spiplan->nargs + 1) * sizeof(ParamListInfoData));
eState->es_param_list_info = paramLI;
for (k = 0; k < spiplan->nargs; paramLI++, k++)
@@ -1192,7 +1193,9 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, char *Nulls, int tcount)
int k;
paramLI = (ParamListInfo)
- palloc0((nargs + 1) * sizeof(ParamListInfoData));
+ palloc((nargs + 1) * sizeof(ParamListInfoData));
+ MemSet(paramLI, 0,
+ (nargs + 1) * sizeof(ParamListInfoData));
state->es_param_list_info = paramLI;
for (k = 0; k < plan->nargs; paramLI++, k++)
diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index c0da123d5d..7fd5a5c1e4 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -460,7 +460,8 @@ make_one_rel_by_joins(Query *root, int levels_needed, List *initial_rels)
* joinitems[j] is a list of all the j-item rels. Initially we set
* joinitems[1] to represent all the single-jointree-item relations.
*/
- joinitems = (List **) palloc0((levels_needed + 1) * sizeof(List *));
+ joinitems = (List **) palloc((levels_needed + 1) * sizeof(List *));
+ MemSet(joinitems, 0, (levels_needed + 1) * sizeof(List *));
joinitems[1] = initial_rels;
diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c
index 845a55dfd8..815f93ef49 100644
--- a/src/backend/parser/parse_func.c
+++ b/src/backend/parser/parse_func.c
@@ -1070,7 +1070,8 @@ gen_cross_product(InhPaths *arginh, int nargs)
/* compute the cross product from right to left */
for (;;)
{
- oneres = (Oid *) palloc0(FUNC_MAX_ARGS * sizeof(Oid));
+ oneres = (Oid *) palloc(FUNC_MAX_ARGS * sizeof(Oid));
+ MemSet(oneres, 0, FUNC_MAX_ARGS * sizeof(Oid));
for (i = nargs - 1; i >= 0 && cur[i] > arginh[i].nsupers; i--)
continue;
diff --git a/src/backend/parser/parse_node.c b/src/backend/parser/parse_node.c
index 7beab4d06b..5dcf73ac36 100644
--- a/src/backend/parser/parse_node.c
+++ b/src/backend/parser/parse_node.c
@@ -40,7 +40,8 @@ make_parsestate(ParseState *parentParseState)
{
ParseState *pstate;
- pstate = palloc0(sizeof(ParseState));
+ pstate = palloc(sizeof(ParseState));
+ MemSet(pstate, 0, sizeof(ParseState));
pstate->parentParseState = parentParseState;
pstate->p_last_resno = 1;
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 0983245135..1354338040 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -1092,8 +1092,10 @@ ProcessStartupPacket(Port *port, bool SSLdone)
if (len < sizeof(ProtocolVersion) || len > sizeof(StartupPacket))
elog(FATAL, "invalid length of startup packet");
+ buf = palloc(sizeof(StartupPacket));
+
/* Ensure we see zeroes for any bytes not sent */
- buf = palloc0(sizeof(StartupPacket));
+ MemSet(buf, 0, sizeof(StartupPacket));
if (pq_getbytes(buf, len) == EOF)
{
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index 892d9d16b7..de0dd553b9 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -248,7 +248,8 @@ makeacl(int n)
if (n < 0)
elog(ERROR, "makeacl: invalid size: %d", n);
size = ACL_N_SIZE(n);
- new_acl = (Acl *) palloc0(size);
+ new_acl = (Acl *) palloc(size);
+ MemSet((char *) new_acl, 0, size);
new_acl->size = size;
new_acl->ndim = 1;
new_acl->flags = 0;
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index 871c0fc5ed..fdfa501792 100644
--- a/src/backend/utils/adt/arrayfuncs.c
+++ b/src/backend/utils/adt/arrayfuncs.c
@@ -235,7 +235,8 @@ array_in(PG_FUNCTION_ARGS)
if (nitems == 0)
{
/* Return empty array */
- retval = (ArrayType *) palloc0(sizeof(ArrayType));
+ retval = (ArrayType *) palloc(sizeof(ArrayType));
+ MemSet(retval, 0, sizeof(ArrayType));
retval->size = sizeof(ArrayType);
retval->elemtype = element_type;
PG_RETURN_ARRAYTYPE_P(retval);
@@ -248,7 +249,8 @@ array_in(PG_FUNCTION_ARGS)
typmod, typdelim, typlen, typbyval, typalign,
&nbytes);
nbytes += ARR_OVERHEAD(ndim);
- retval = (ArrayType *) palloc0(nbytes);
+ retval = (ArrayType *) palloc(nbytes);
+ MemSet(retval, 0, nbytes);
retval->size = nbytes;
retval->ndim = ndim;
retval->elemtype = element_type;
@@ -395,7 +397,8 @@ ReadArrayStr(char *arrayStr,
prod[MAXDIM];
mda_get_prod(ndim, dim, prod);
- values = (Datum *) palloc0(nitems * sizeof(Datum));
+ values = (Datum *) palloc(nitems * sizeof(Datum));
+ MemSet(values, 0, nitems * sizeof(Datum));
MemSet(indx, 0, sizeof(indx));
/* read array enclosed within {} */
@@ -511,7 +514,10 @@ ReadArrayStr(char *arrayStr,
if (!typbyval)
for (i = 0; i < nitems; i++)
if (values[i] == (Datum) 0)
- values[i] = PointerGetDatum(palloc0(typlen));
+ {
+ values[i] = PointerGetDatum(palloc(typlen));
+ MemSet(DatumGetPointer(values[i]), 0, typlen);
+ }
}
else
{
@@ -1587,7 +1593,8 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType)
/* Allocate and initialize the result array */
nbytes += ARR_OVERHEAD(ndim);
- result = (ArrayType *) palloc0(nbytes);
+ result = (ArrayType *) palloc(nbytes);
+ MemSet(result, 0, nbytes);
result->size = nbytes;
result->ndim = ndim;
diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c
index 9b72c54a88..f4d6416fad 100644
--- a/src/backend/utils/adt/geo_ops.c
+++ b/src/backend/utils/adt/geo_ops.c
@@ -3130,8 +3130,9 @@ poly_in(PG_FUNCTION_ARGS)
elog(ERROR, "Bad polygon external representation '%s'", str);
size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * npts;
- poly = (POLYGON *) palloc0(size); /* zero any holes */
+ poly = (POLYGON *) palloc(size);
+ MemSet((char *) poly, 0, size); /* zero any holes */
poly->size = size;
poly->npts = npts;
@@ -4451,7 +4452,9 @@ circle_poly(PG_FUNCTION_ARGS)
if (base_size / npts != sizeof(poly->p[0]) || size <= base_size)
elog(ERROR, "too many points requested");
- poly = (POLYGON *) palloc0(size); /* zero any holes */
+ poly = (POLYGON *) palloc(size);
+
+ MemSet(poly, 0, size); /* zero any holes */
poly->size = size;
poly->npts = npts;
diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c
index 878318b271..ae5f0c37a3 100644
--- a/src/backend/utils/adt/network.c
+++ b/src/backend/utils/adt/network.c
@@ -51,8 +51,9 @@ network_in(char *src, int type)
int bits;
inet *dst;
+ dst = (inet *) palloc(VARHDRSZ + sizeof(inet_struct));
/* make sure any unused bits in a CIDR value are zeroed */
- dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct));
+ MemSet(dst, 0, VARHDRSZ + sizeof(inet_struct));
/* First, try for an IP V4 address: */
ip_family(dst) = AF_INET;
@@ -493,8 +494,9 @@ network_broadcast(PG_FUNCTION_ARGS)
inet *ip = PG_GETARG_INET_P(0);
inet *dst;
+ dst = (inet *) palloc(VARHDRSZ + sizeof(inet_struct));
/* make sure any unused bits are zeroed */
- dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct));
+ MemSet(dst, 0, VARHDRSZ + sizeof(inet_struct));
if (ip_family(ip) == AF_INET)
{
@@ -532,8 +534,9 @@ network_network(PG_FUNCTION_ARGS)
inet *ip = PG_GETARG_INET_P(0);
inet *dst;
+ dst = (inet *) palloc(VARHDRSZ + sizeof(inet_struct));
/* make sure any unused bits are zeroed */
- dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct));
+ MemSet(dst, 0, VARHDRSZ + sizeof(inet_struct));
if (ip_family(ip) == AF_INET)
{
@@ -571,8 +574,9 @@ network_netmask(PG_FUNCTION_ARGS)
inet *ip = PG_GETARG_INET_P(0);
inet *dst;
+ dst = (inet *) palloc(VARHDRSZ + sizeof(inet_struct));
/* make sure any unused bits are zeroed */
- dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct));
+ MemSet(dst, 0, VARHDRSZ + sizeof(inet_struct));
if (ip_family(ip) == AF_INET)
{
diff --git a/src/backend/utils/adt/varbit.c b/src/backend/utils/adt/varbit.c
index 2d4a45557f..8fde057d86 100644
--- a/src/backend/utils/adt/varbit.c
+++ b/src/backend/utils/adt/varbit.c
@@ -107,8 +107,9 @@ bit_in(PG_FUNCTION_ARGS)
bitlen, atttypmod);
len = VARBITTOTALLEN(atttypmod);
+ result = (VarBit *) palloc(len);
/* set to 0 so that *r is always initialised and string is zero-padded */
- result = (VarBit *) palloc0(len);
+ MemSet(result, 0, len);
VARATT_SIZEP(result) = len;
VARBITLEN(result) = atttypmod;
@@ -231,8 +232,9 @@ bit(PG_FUNCTION_ARGS)
VARBITLEN(arg), len);
rlen = VARBITTOTALLEN(len);
+ result = (VarBit *) palloc(rlen);
/* set to 0 so that string is zero-padded */
- result = (VarBit *) palloc0(rlen);
+ MemSet(result, 0, rlen);
VARATT_SIZEP(result) = rlen;
VARBITLEN(result) = len;
@@ -314,8 +316,9 @@ varbit_in(PG_FUNCTION_ARGS)
atttypmod);
len = VARBITTOTALLEN(bitlen);
+ result = (VarBit *) palloc(len);
/* set to 0 so that *r is always initialised and string is zero-padded */
- result = (VarBit *) palloc0(len);
+ MemSet(result, 0, len);
VARATT_SIZEP(result) = len;
VARBITLEN(result) = Min(bitlen, atttypmod);
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index 99808c5c3a..a8070069db 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -808,7 +808,8 @@ InitCatCache(int id,
*
* Note: we assume zeroing initializes the Dllist headers correctly
*/
- cp = (CatCache *) palloc0(sizeof(CatCache) + NCCBUCKETS * sizeof(Dllist));
+ cp = (CatCache *) palloc(sizeof(CatCache) + NCCBUCKETS * sizeof(Dllist));
+ MemSet((char *) cp, 0, sizeof(CatCache) + NCCBUCKETS * sizeof(Dllist));
/*
* initialize the cache's relation information for the relation
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 59747647c8..3b0ddd3ab0 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -1348,9 +1348,13 @@ formrdesc(const char *relationName,
/*
* allocate new relation desc
+ */
+ relation = (Relation) palloc(sizeof(RelationData));
+
+ /*
* clear all fields of reldesc
*/
- relation = (Relation) palloc0(sizeof(RelationData));
+ MemSet((char *) relation, 0, sizeof(RelationData));
relation->rd_targblock = InvalidBlockNumber;
/* make sure relation is marked as having no open file yet */
@@ -1376,7 +1380,8 @@ formrdesc(const char *relationName,
* get us launched. RelationCacheInitializePhase2() will read the
* real data from pg_class and replace what we've done here.
*/
- relation->rd_rel = (Form_pg_class) palloc0(CLASS_TUPLE_SIZE);
+ relation->rd_rel = (Form_pg_class) palloc(CLASS_TUPLE_SIZE);
+ MemSet(relation->rd_rel, 0, CLASS_TUPLE_SIZE);
namestrcpy(&relation->rd_rel->relname, relationName);
relation->rd_rel->relnamespace = PG_CATALOG_NAMESPACE;
@@ -2049,7 +2054,8 @@ RelationBuildLocalRelation(const char *relname,
/*
* allocate a new relation descriptor and fill in basic state fields.
*/
- rel = (Relation) palloc0(sizeof(RelationData));
+ rel = (Relation) palloc(sizeof(RelationData));
+ MemSet((char *) rel, 0, sizeof(RelationData));
rel->rd_targblock = InvalidBlockNumber;
@@ -2087,7 +2093,8 @@ RelationBuildLocalRelation(const char *relname,
/*
* initialize relation tuple form (caller may add/override data later)
*/
- rel->rd_rel = (Form_pg_class) palloc0(CLASS_TUPLE_SIZE);
+ rel->rd_rel = (Form_pg_class) palloc(CLASS_TUPLE_SIZE);
+ MemSet((char *) rel->rd_rel, 0, CLASS_TUPLE_SIZE);
namestrcpy(&rel->rd_rel->relname, relname);
rel->rd_rel->relnamespace = relnamespace;
diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c
index b812d58d5c..04490562e6 100644
--- a/src/backend/utils/fmgr/fmgr.c
+++ b/src/backend/utils/fmgr/fmgr.c
@@ -1550,8 +1550,9 @@ Int64GetDatum(int64 X)
* with zeroes in the unused bits. This is needed so that, for
* example, hash join of int8 will behave properly.
*/
- int64 *retval = (int64 *) palloc0(Max(sizeof(int64), 8));
+ int64 *retval = (int64 *) palloc(Max(sizeof(int64), 8));
+ MemSet(retval, 0, Max(sizeof(int64), 8));
*retval = X;
return PointerGetDatum(retval);
#endif /* INT64_IS_BUSTED */
diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c
index d04d143f92..ca69c3b040 100644
--- a/src/backend/utils/sort/tuplesort.c
+++ b/src/backend/utils/sort/tuplesort.c
@@ -414,7 +414,9 @@ tuplesort_begin_common(bool randomAccess)
{
Tuplesortstate *state;
- state = (Tuplesortstate *) palloc0(sizeof(Tuplesortstate));
+ state = (Tuplesortstate *) palloc(sizeof(Tuplesortstate));
+
+ MemSet((char *) state, 0, sizeof(Tuplesortstate));
state->status = TSS_INITIAL;
state->randomAccess = randomAccess;
@@ -457,9 +459,11 @@ tuplesort_begin_heap(TupleDesc tupDesc,
state->tupDesc = tupDesc;
state->nKeys = nkeys;
- state->scanKeys = (ScanKey) palloc0(nkeys * sizeof(ScanKeyData));
+ state->scanKeys = (ScanKey) palloc(nkeys * sizeof(ScanKeyData));
+ MemSet(state->scanKeys, 0, nkeys * sizeof(ScanKeyData));
state->sortFnKinds = (SortFunctionKind *)
- palloc0(nkeys * sizeof(SortFunctionKind));
+ palloc(nkeys * sizeof(SortFunctionKind));
+ MemSet(state->sortFnKinds, 0, nkeys * sizeof(SortFunctionKind));
for (i = 0; i < nkeys; i++)
{
diff --git a/src/backend/utils/sort/tuplestore.c b/src/backend/utils/sort/tuplestore.c
index 0bab14861f..4aa590b391 100644
--- a/src/backend/utils/sort/tuplestore.c
+++ b/src/backend/utils/sort/tuplestore.c
@@ -197,7 +197,9 @@ tuplestore_begin_common(bool randomAccess, int maxKBytes)
{
Tuplestorestate *state;
- state = (Tuplestorestate *) palloc0(sizeof(Tuplestorestate));
+ state = (Tuplestorestate *) palloc(sizeof(Tuplestorestate));
+
+ MemSet((char *) state, 0, sizeof(Tuplestorestate));
state->status = TSS_INITIAL;
state->randomAccess = randomAccess;
diff --git a/src/include/c.h b/src/include/c.h
index 906000b74b..40944902de 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -586,8 +586,7 @@ typedef NameData *Name;
int _val = (val); \
Size _len = (len); \
\
- if ((((long) _start) & INT_ALIGN_MASK) == 0 && \
- (_len & INT_ALIGN_MASK) == 0 && \
+ if ((( ((long) _start) | _len) & INT_ALIGN_MASK) == 0 && \
_val == 0 && \
_len <= MEMSET_LOOP_LIMIT) \
{ \
diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c
index 09b8157f65..4494097249 100644
--- a/src/pl/plpgsql/src/pl_exec.c
+++ b/src/pl/plpgsql/src/pl_exec.c
@@ -1008,7 +1008,7 @@ exec_stmt_perform(PLpgSQL_execstate * estate, PLpgSQL_stmt_perform * stmt)
*/
if (expr->plan == NULL)
exec_prepare_plan(estate, expr);
-
+
rc = exec_run_select(estate, expr, 0, NULL);
if (rc != SPI_OK_SELECT)
elog(ERROR, "query \"%s\" didn't return data", expr->query);
@@ -1627,8 +1627,9 @@ exec_stmt_return_next(PLpgSQL_execstate * estate,
if (natts != stmt->row->nfields)
elog(ERROR, "Wrong record type supplied in RETURN NEXT");
- dvalues = (Datum *) palloc0(natts * sizeof(Datum));
+ dvalues = (Datum *) palloc(natts * sizeof(Datum));
nulls = (char *) palloc(natts * sizeof(char));
+ MemSet(dvalues, 0, natts * sizeof(Datum));
MemSet(nulls, 'n', natts);
for (i = 0; i < natts; i++)
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index 37123f0aac..1b3cc9d243 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -300,11 +300,12 @@ reverse_name(char *string)
int len;
char *new_string;
- if (!(new_string = palloc0(NAMEDATALEN)))
+ if (!(new_string = palloc(NAMEDATALEN)))
{
fprintf(stderr, "reverse_name: palloc failed\n");
return NULL;
}
+ MemSet(new_string, 0, NAMEDATALEN);
for (i = 0; i < NAMEDATALEN && string[i]; ++i)
;
if (i == NAMEDATALEN || !string[i])