From 5015e1e1b58f81a036e4ad16291ef4b3bb7a596c Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 12 Sep 2022 08:31:56 +0200 Subject: 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 Discussion: https://www.postgresql.org/message-id/flat/bb755632-2a43-d523-36f8-a1e7a389a907@enterprisedb.com --- src/bin/pg_dump/pg_backup_tar.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/bin/pg_dump/pg_backup_tar.c') diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c index bfc49b66d2c..7960b81c0e6 100644 --- a/src/bin/pg_dump/pg_backup_tar.c +++ b/src/bin/pg_dump/pg_backup_tar.c @@ -151,7 +151,7 @@ InitArchiveFmt_Tar(ArchiveHandle *AH) /* * Set up some special context used in compressing data. */ - ctx = (lclContext *) pg_malloc0(sizeof(lclContext)); + ctx = pg_malloc0_object(lclContext); AH->formatData = (void *) ctx; ctx->filePos = 0; ctx->isSpecialScript = 0; @@ -240,7 +240,7 @@ _ArchiveEntry(ArchiveHandle *AH, TocEntry *te) lclTocEntry *ctx; char fn[K_STD_BUF_SIZE]; - ctx = (lclTocEntry *) pg_malloc0(sizeof(lclTocEntry)); + ctx = pg_malloc0_object(lclTocEntry); if (te->dataDumper != NULL) { snprintf(fn, sizeof(fn), "%d.dat", te->dumpId); @@ -272,7 +272,7 @@ _ReadExtraToc(ArchiveHandle *AH, TocEntry *te) if (ctx == NULL) { - ctx = (lclTocEntry *) pg_malloc0(sizeof(lclTocEntry)); + ctx = pg_malloc0_object(lclTocEntry); te->formatData = (void *) ctx; } @@ -337,7 +337,7 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode) { int old_umask; - tm = pg_malloc0(sizeof(TAR_MEMBER)); + tm = pg_malloc0_object(TAR_MEMBER); /* * POSIX does not require, but permits, tmpfile() to restrict file @@ -1052,7 +1052,7 @@ static TAR_MEMBER * _tarPositionTo(ArchiveHandle *AH, const char *filename) { lclContext *ctx = (lclContext *) AH->formatData; - TAR_MEMBER *th = pg_malloc0(sizeof(TAR_MEMBER)); + TAR_MEMBER *th = pg_malloc0_object(TAR_MEMBER); char c; char header[TAR_BLOCK_SIZE]; size_t i, -- cgit v1.2.3