Skip to content

Commit 1983af8

Browse files
committed
Switch some palloc/memset calls to palloc0
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
1 parent 5bde165 commit 1983af8

File tree

5 files changed

+6
-13
lines changed

5 files changed

+6
-13
lines changed

contrib/tablefunc/tablefunc.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -867,11 +867,8 @@ get_crosstab_tuplestore(char *sql,
867867
"tuple has %d columns but crosstab " \
868868
"returns %d.", tupdesc->natts, result_ncols)));
869869

870-
/* allocate space */
871-
values = (char **) palloc(result_ncols * sizeof(char *));
872-
873-
/* and make sure it's clear */
874-
memset(values, '\0', result_ncols * sizeof(char *));
870+
/* allocate space and make sure it's clear */
871+
values = (char **) palloc0(result_ncols * sizeof(char *));
875872

876873
for (i = 0; i < proc; i++)
877874
{

src/backend/access/gist/gist.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ static void gistprunepage(Relation rel, Page page, Buffer buffer,
4343

4444

4545
#define ROTATEDIST(d) do { \
46-
SplitedPageLayout *tmp=(SplitedPageLayout*)palloc(sizeof(SplitedPageLayout)); \
47-
memset(tmp,0,sizeof(SplitedPageLayout)); \
46+
SplitedPageLayout *tmp=(SplitedPageLayout*)palloc0(sizeof(SplitedPageLayout)); \
4847
tmp->block.blkno = InvalidBlockNumber; \
4948
tmp->buffer = InvalidBuffer; \
5049
tmp->next = (d); \

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,8 +1382,7 @@ SortTocFromFile(Archive *AHX)
13821382
bool incomplete_line;
13831383

13841384
/* Allocate space for the 'wanted' array, and init it */
1385-
ropt->idWanted = (bool *) pg_malloc(sizeof(bool) * AH->maxDumpId);
1386-
memset(ropt->idWanted, 0, sizeof(bool) * AH->maxDumpId);
1385+
ropt->idWanted = (bool *) pg_malloc0(sizeof(bool) * AH->maxDumpId);
13871386

13881387
/* Setup the file */
13891388
fh = fopen(ropt->tocFile, PG_BINARY_R);

src/bin/pg_dump/pg_dump_sort.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,7 @@ TopoSort(DumpableObject **objs,
320320
* We also make a map showing the input-order index of the item with
321321
* dumpId j.
322322
*/
323-
beforeConstraints = (int *) pg_malloc((maxDumpId + 1) * sizeof(int));
324-
memset(beforeConstraints, 0, (maxDumpId + 1) * sizeof(int));
323+
beforeConstraints = (int *) pg_malloc0((maxDumpId + 1) * sizeof(int));
325324
idMap = (int *) pg_malloc((maxDumpId + 1) * sizeof(int));
326325
for (i = 0; i < numObjs; i++)
327326
{

src/bin/pgbench/pgbench.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5301,8 +5301,7 @@ main(int argc, char **argv)
53015301
else if ((env = getenv("PGUSER")) != NULL && *env != '\0')
53025302
login = env;
53035303

5304-
state = (CState *) pg_malloc(sizeof(CState));
5305-
memset(state, 0, sizeof(CState));
5304+
state = (CState *) pg_malloc0(sizeof(CState));
53065305

53075306
/* set random seed early, because it may be used while parsing scripts. */
53085307
if (!set_random_seed(getenv("PGBENCH_RANDOM_SEED")))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy