Switch some palloc/memset calls to palloc0
authorMichael Paquier <michael@paquier.xyz>
Wed, 27 Mar 2019 03:02:50 +0000 (12:02 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 27 Mar 2019 03:02:50 +0000 (12:02 +0900)
Some code paths have been doing some allocations followed by an
immediate memset() to initialize the allocated area with zeros, this is
a bit overkill as there are already interfaces to do both things in one
call.

Author: Daniel Gustafsson
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/vN0OodBPkKs7g2Z1uyk3CUEmhdtspHgYCImhlmSxv1Xn6nY1ZnaaGHL8EWUIQ-NEv36tyc4G5-uA3UXUF2l4sFXtK_EQgLN1hcgunlFVKhA=@yesql.se

contrib/tablefunc/tablefunc.c
src/backend/access/gist/gist.c
src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_dump_sort.c
src/bin/pgbench/pgbench.c

index 02e49214101b315eee2917ff846e19d5f967fcff..cd02495c451e84e771e20c129721034d5462ac5b 100644 (file)
@@ -867,11 +867,8 @@ get_crosstab_tuplestore(char *sql,
                               "tuple has %d columns but crosstab " \
                               "returns %d.", tupdesc->natts, result_ncols)));
 
-       /* allocate space */
-       values = (char **) palloc(result_ncols * sizeof(char *));
-
-       /* and make sure it's clear */
-       memset(values, '\0', result_ncols * sizeof(char *));
+       /* allocate space and make sure it's clear */
+       values = (char **) palloc0(result_ncols * sizeof(char *));
 
        for (i = 0; i < proc; i++)
        {
index a746e911f37c3e1f31721884a05bc3c906b2ed2c..2fddb23496d02763b8413bf01d419e99556d93a9 100644 (file)
@@ -43,8 +43,7 @@ static void gistprunepage(Relation rel, Page page, Buffer buffer,
 
 
 #define ROTATEDIST(d) do { \
-   SplitedPageLayout *tmp=(SplitedPageLayout*)palloc(sizeof(SplitedPageLayout)); \
-   memset(tmp,0,sizeof(SplitedPageLayout)); \
+   SplitedPageLayout *tmp=(SplitedPageLayout*)palloc0(sizeof(SplitedPageLayout)); \
    tmp->block.blkno = InvalidBlockNumber;  \
    tmp->buffer = InvalidBuffer;    \
    tmp->next = (d); \
index 2266c99b33f4aa39d3e9af88a41e9ea67987547d..6131cdda96c12167a0e8045cd2bc0006abfe7d70 100644 (file)
@@ -1382,8 +1382,7 @@ SortTocFromFile(Archive *AHX)
    bool        incomplete_line;
 
    /* Allocate space for the 'wanted' array, and init it */
-   ropt->idWanted = (bool *) pg_malloc(sizeof(bool) * AH->maxDumpId);
-   memset(ropt->idWanted, 0, sizeof(bool) * AH->maxDumpId);
+   ropt->idWanted = (bool *) pg_malloc0(sizeof(bool) * AH->maxDumpId);
 
    /* Setup the file */
    fh = fopen(ropt->tocFile, PG_BINARY_R);
index bb128c89f3c024dd5d1be3e55cdfcc46f328b8f7..a7a5b1e7f7d254bc266e38ee518bc8cce1986e68 100644 (file)
@@ -320,8 +320,7 @@ TopoSort(DumpableObject **objs,
     * We also make a map showing the input-order index of the item with
     * dumpId j.
     */
-   beforeConstraints = (int *) pg_malloc((maxDumpId + 1) * sizeof(int));
-   memset(beforeConstraints, 0, (maxDumpId + 1) * sizeof(int));
+   beforeConstraints = (int *) pg_malloc0((maxDumpId + 1) * sizeof(int));
    idMap = (int *) pg_malloc((maxDumpId + 1) * sizeof(int));
    for (i = 0; i < numObjs; i++)
    {
index b1afe44817b070ba7d2c07ba79623d939e43611c..cdd21d7469f65e1c7d9b06c6632bb9f85155adde 100644 (file)
@@ -5301,8 +5301,7 @@ main(int argc, char **argv)
    else if ((env = getenv("PGUSER")) != NULL && *env != '\0')
        login = env;
 
-   state = (CState *) pg_malloc(sizeof(CState));
-   memset(state, 0, sizeof(CState));
+   state = (CState *) pg_malloc0(sizeof(CState));
 
    /* set random seed early, because it may be used while parsing scripts. */
    if (!set_random_seed(getenv("PGBENCH_RANDOM_SEED")))