Use calloc() to allocate empty structures.
authorBruce Momjian <bruce@momjian.us>
Wed, 8 Oct 2003 03:52:32 +0000 (03:52 +0000)
committerBruce Momjian <bruce@momjian.us>
Wed, 8 Oct 2003 03:52:32 +0000 (03:52 +0000)
Fix pg_restore tar log output bug where Special flag wasn't being
initialized; bug seen on XP.

src/bin/pg_dump/pg_backup_custom.c
src/bin/pg_dump/pg_backup_files.c
src/bin/pg_dump/pg_backup_tar.c
src/bin/pg_dump/pg_dump.c

index c45d468361f0598b3d1b37592bd0c8a007821d6d..a32a179ead92f981914522a13ba95c8485e959a0 100644 (file)
@@ -136,7 +136,7 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
        /*
         * Set up some special context used in compressing data.
         */
-       ctx = (lclContext *) malloc(sizeof(lclContext));
+       ctx = (lclContext *) calloc(1, sizeof(lclContext));
        if (ctx == NULL)
                die_horribly(AH, modulename, "out of memory\n");
        AH->formatData = (void *) ctx;
@@ -253,7 +253,7 @@ _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
 
        if (ctx == NULL)
        {
-               ctx = (lclTocEntry *) malloc(sizeof(lclTocEntry));
+               ctx = (lclTocEntry *) calloc(1, sizeof(lclTocEntry));
                te->formatData = (void *) ctx;
        }
 
index 15397d824a98766ed2e049489c0301a5bc550468..053ece732375e644f1271e5f717725c35dfb41b0 100644 (file)
@@ -101,7 +101,7 @@ InitArchiveFmt_Files(ArchiveHandle *AH)
        /*
         * Set up some special context used in compressing data.
         */
-       ctx = (lclContext *) malloc(sizeof(lclContext));
+       ctx = (lclContext *) calloc(1, sizeof(lclContext));
        AH->formatData = (void *) ctx;
        ctx->filePos = 0;
 
@@ -167,7 +167,7 @@ _ArchiveEntry(ArchiveHandle *AH, TocEntry *te)
        lclTocEntry *ctx;
        char            fn[K_STD_BUF_SIZE];
 
-       ctx = (lclTocEntry *) malloc(sizeof(lclTocEntry));
+       ctx = (lclTocEntry *) calloc(1, sizeof(lclTocEntry));
        if (te->dataDumper)
        {
 #ifdef HAVE_LIBZ
@@ -206,7 +206,7 @@ _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
 
        if (ctx == NULL)
        {
-               ctx = (lclTocEntry *) malloc(sizeof(lclTocEntry));
+               ctx = (lclTocEntry *) calloc(1, sizeof(lclTocEntry));
                te->formatData = (void *) ctx;
        }
 
index dc6fedf40cad2484daea626183da9db160a83772..1465585f90896468ce3d266207889e47c9ae14a5 100644 (file)
@@ -158,10 +158,11 @@ InitArchiveFmt_Tar(ArchiveHandle *AH)
        /*
         * Set up some special context used in compressing data.
         */
-       ctx = (lclContext *) malloc(sizeof(lclContext));
+       ctx = (lclContext *) calloc(1, sizeof(lclContext));
        AH->formatData = (void *) ctx;
        ctx->filePos = 0;
-
+       ctx->isSpecialScript = 0;
+       
        /* Initialize LO buffering */
        AH->lo_buf_size = LOBBUFSIZE;
        AH->lo_buf = (void *) malloc(LOBBUFSIZE);
@@ -253,7 +254,7 @@ _ArchiveEntry(ArchiveHandle *AH, TocEntry *te)
        lclTocEntry *ctx;
        char            fn[K_STD_BUF_SIZE];
 
-       ctx = (lclTocEntry *) malloc(sizeof(lclTocEntry));
+       ctx = (lclTocEntry *) calloc(1, sizeof(lclTocEntry));
        if (te->dataDumper != NULL)
        {
 #ifdef HAVE_LIBZ
@@ -292,7 +293,7 @@ _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
 
        if (ctx == NULL)
        {
-               ctx = (lclTocEntry *) malloc(sizeof(lclTocEntry));
+               ctx = (lclTocEntry *) calloc(1, sizeof(lclTocEntry));
                te->formatData = (void *) ctx;
        }
 
index df6405953ec1d6b46c91804638e1bc1494ddc615..ea68a486bbc9290cd663f8ad215ea7437e193914 100644 (file)
@@ -1078,7 +1078,7 @@ dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout,
                                write_msg(NULL, "preparing to dump the contents of table %s\n",
                                                  classname);
 
-                       dumpCtx = (DumpContext *) malloc(sizeof(DumpContext));
+                       dumpCtx = (DumpContext *) calloc(1, sizeof(DumpContext));
                        dumpCtx->tblinfo = (TableInfo *) tblinfo;
                        dumpCtx->tblidx = i;
                        dumpCtx->oids = oids;
@@ -1938,9 +1938,7 @@ getFuncs(int *numFuncs)
 
        *numFuncs = ntups;
 
-       finfo = (FuncInfo *) malloc(ntups * sizeof(FuncInfo));
-
-       memset((char *) finfo, 0, ntups * sizeof(FuncInfo));
+       finfo = (FuncInfo *) calloc(ntups, sizeof(FuncInfo));
 
        i_oid = PQfnumber(res, "oid");
        i_proname = PQfnumber(res, "proname");
@@ -2144,8 +2142,7 @@ getTables(int *numTables)
         * dumping only one, because we don't yet know which tables might be
         * inheritance ancestors of the target table.
         */
-       tblinfo = (TableInfo *) malloc(ntups * sizeof(TableInfo));
-       memset(tblinfo, 0, ntups * sizeof(TableInfo));
+       tblinfo = (TableInfo *) calloc(ntups, sizeof(TableInfo));
 
        i_reloid = PQfnumber(res, "oid");
        i_relname = PQfnumber(res, "relname");