]> granicus.if.org Git - postgresql/blobdiff - src/bin/pg_dump/pg_backup_custom.c
Modify pg_dump to use error-free memory allocation macros. This avoids
[postgresql] / src / bin / pg_dump / pg_backup_custom.c
index a28c15ab3ea1060602892bd8dd16c10cb317fd35..bfdf482a6b268a2cdfbdd88009c2c0aadb736348 100644 (file)
@@ -24,8 +24,8 @@
  *-------------------------------------------------------------------------
  */
 
-#include "pg_backup_archiver.h"
 #include "compress_io.h"
+#include "common.h"
 
 /*--------
  * Routines in the format interface
@@ -127,16 +127,12 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
        AH->DeClonePtr = _DeClone;
 
        /* Set up a private area. */
-       ctx = (lclContext *) calloc(1, sizeof(lclContext));
-       if (ctx == NULL)
-               die_horribly(AH, modulename, "out of memory\n");
+       ctx = (lclContext *) pg_calloc(1, sizeof(lclContext));
        AH->formatData = (void *) ctx;
 
        /* Initialize LO buffering */
        AH->lo_buf_size = LOBBUFSIZE;
-       AH->lo_buf = (void *) malloc(LOBBUFSIZE);
-       if (AH->lo_buf == NULL)
-               die_horribly(AH, modulename, "out of memory\n");
+       AH->lo_buf = (void *) pg_malloc(LOBBUFSIZE);
 
        ctx->filePos = 0;
 
@@ -200,7 +196,7 @@ _ArchiveEntry(ArchiveHandle *AH, TocEntry *te)
 {
        lclTocEntry *ctx;
 
-       ctx = (lclTocEntry *) calloc(1, sizeof(lclTocEntry));
+       ctx = (lclTocEntry *) pg_calloc(1, sizeof(lclTocEntry));
        if (te->dataDumper)
                ctx->dataState = K_OFFSET_POS_NOT_SET;
        else
@@ -237,12 +233,11 @@ _WriteExtraToc(ArchiveHandle *AH, TocEntry *te)
 static void
 _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
 {
-       int                     junk;
        lclTocEntry *ctx = (lclTocEntry *) te->formatData;
 
        if (ctx == NULL)
        {
-               ctx = (lclTocEntry *) calloc(1, sizeof(lclTocEntry));
+               ctx = (lclTocEntry *) pg_calloc(1, sizeof(lclTocEntry));
                te->formatData = (void *) ctx;
        }
 
@@ -253,7 +248,7 @@ _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
         * dump it at all.
         */
        if (AH->version < K_VERS_1_7)
-               junk = ReadInt(AH);
+               ReadInt(AH);
 }
 
 /*
@@ -568,7 +563,7 @@ _skipData(ArchiveHandle *AH)
                {
                        if (buf)
                                free(buf);
-                       buf = (char *) malloc(blkLen);
+                       buf = (char *) pg_malloc(blkLen);
                        buflen = blkLen;
                }
                cnt = fread(buf, 1, blkLen, AH->FH);
@@ -736,10 +731,15 @@ _ReopenArchive(ArchiveHandle *AH)
 
        if (AH->mode == archModeWrite)
                die_horribly(AH, modulename, "can only reopen input archives\n");
+
+       /*
+        * These two cases are user-facing errors since they represent unsupported
+        * (but not invalid) use-cases.  Word the error messages appropriately.
+        */
        if (AH->fSpec == NULL || strcmp(AH->fSpec, "") == 0)
-               die_horribly(AH, modulename, "cannot reopen stdin\n");
+               die_horribly(AH, modulename, "parallel restore from stdin is not supported\n");
        if (!ctx->hasSeek)
-               die_horribly(AH, modulename, "cannot reopen non-seekable file\n");
+               die_horribly(AH, modulename, "parallel restore from non-seekable file is not supported\n");
 
        errno = 0;
        tpos = ftello(AH->FH);
@@ -771,9 +771,7 @@ _Clone(ArchiveHandle *AH)
 {
        lclContext *ctx = (lclContext *) AH->formatData;
 
-       AH->formatData = (lclContext *) malloc(sizeof(lclContext));
-       if (AH->formatData == NULL)
-               die_horribly(AH, modulename, "out of memory\n");
+       AH->formatData = (lclContext *) pg_malloc(sizeof(lclContext));
        memcpy(AH->formatData, ctx, sizeof(lclContext));
        ctx = (lclContext *) AH->formatData;
 
@@ -898,9 +896,7 @@ _CustomReadFunc(ArchiveHandle *AH, char **buf, size_t *buflen)
        if (blkLen > *buflen)
        {
                free(*buf);
-               *buf = (char *) malloc(blkLen);
-               if (!(*buf))
-                       die_horribly(AH, modulename, "out of memory\n");
+               *buf = (char *) pg_malloc(blkLen);
                *buflen = blkLen;
        }