From ff392559f5db2c445dfee007974350dbc39b8e86 Mon Sep 17 00:00:00 2001 From: Daniel Gustafsson Date: Mon, 25 Mar 2019 13:48:36 +0100 Subject: [PATCH] Use pg_malloc0() for zeroed out allocations Replace the few codepaths that still do pg_malloc()+memset() with using pg_malloc0() directly. --- src/bin/pg_dump/pg_backup_archiver.c | 3 +-- src/bin/pg_dump/pg_dump_sort.c | 3 +-- src/bin/pgbench/pgbench.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 62bf1493aa..0288184bf0 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -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); diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c index bb128c89f3..a7a5b1e7f7 100644 --- a/src/bin/pg_dump/pg_dump_sort.c +++ b/src/bin/pg_dump/pg_dump_sort.c @@ -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++) { diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index 4789ab92ee..e30d742a39 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -5305,8 +5305,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"))) -- 2.14.1.145.gb3622a4ee