diff options
Diffstat (limited to 'src/bin/pg_dump/compress_io.c')
-rw-r--r-- | src/bin/pg_dump/compress_io.c | 45 |
1 files changed, 11 insertions, 34 deletions
diff --git a/src/bin/pg_dump/compress_io.c b/src/bin/pg_dump/compress_io.c index 8540a75d113..8375762ff5a 100644 --- a/src/bin/pg_dump/compress_io.c +++ b/src/bin/pg_dump/compress_io.c @@ -53,6 +53,7 @@ */ #include "compress_io.h" +#include "common.h" /*---------------------- * Compressor API @@ -135,9 +136,7 @@ AllocateCompressor(int compression, WriteFunc writeF) die_horribly(NULL, modulename, "not built with zlib support\n"); #endif - cs = (CompressorState *) calloc(1, sizeof(CompressorState)); - if (cs == NULL) - die_horribly(NULL, modulename, "out of memory\n"); + cs = (CompressorState *) pg_calloc(1, sizeof(CompressorState)); cs->writeF = writeF; cs->comprAlg = alg; @@ -221,9 +220,7 @@ InitCompressorZlib(CompressorState *cs, int level) { z_streamp zp; - zp = cs->zp = (z_streamp) malloc(sizeof(z_stream)); - if (cs->zp == NULL) - die_horribly(NULL, modulename, "out of memory\n"); + zp = cs->zp = (z_streamp) pg_malloc(sizeof(z_stream)); zp->zalloc = Z_NULL; zp->zfree = Z_NULL; zp->opaque = Z_NULL; @@ -233,12 +230,9 @@ InitCompressorZlib(CompressorState *cs, int level) * actually allocate one extra byte because some routines want to append a * trailing zero byte to the zlib output. */ - cs->zlibOut = (char *) malloc(ZLIB_OUT_SIZE + 1); + cs->zlibOut = (char *) pg_malloc(ZLIB_OUT_SIZE + 1); cs->zlibOutSize = ZLIB_OUT_SIZE; - if (cs->zlibOut == NULL) - die_horribly(NULL, modulename, "out of memory\n"); - if (deflateInit(zp, level) != Z_OK) die_horribly(NULL, modulename, "could not initialize compression library: %s\n", @@ -338,21 +332,15 @@ ReadDataFromArchiveZlib(ArchiveHandle *AH, ReadFunc readF) char *buf; size_t buflen; - zp = (z_streamp) malloc(sizeof(z_stream)); - if (zp == NULL) - die_horribly(NULL, modulename, "out of memory\n"); + zp = (z_streamp) pg_malloc(sizeof(z_stream)); zp->zalloc = Z_NULL; zp->zfree = Z_NULL; zp->opaque = Z_NULL; - buf = malloc(ZLIB_IN_SIZE); - if (buf == NULL) - die_horribly(NULL, modulename, "out of memory\n"); + buf = pg_malloc(ZLIB_IN_SIZE); buflen = ZLIB_IN_SIZE; - out = malloc(ZLIB_OUT_SIZE + 1); - if (out == NULL) - die_horribly(NULL, modulename, "out of memory\n"); + out = pg_malloc(ZLIB_OUT_SIZE + 1); if (inflateInit(zp) != Z_OK) die_horribly(NULL, modulename, @@ -417,9 +405,7 @@ ReadDataFromArchiveNone(ArchiveHandle *AH, ReadFunc readF) char *buf; size_t buflen; - buf = malloc(ZLIB_OUT_SIZE); - if (buf == NULL) - die_horribly(NULL, modulename, "out of memory\n"); + buf = pg_malloc(ZLIB_OUT_SIZE); buflen = ZLIB_OUT_SIZE; while ((cnt = readF(AH, &buf, &buflen))) @@ -491,10 +477,7 @@ cfopen_read(const char *path, const char *mode) if (fp == NULL) { int fnamelen = strlen(path) + 4; - char *fname = malloc(fnamelen); - - if (fname == NULL) - die_horribly(NULL, modulename, "Out of memory\n"); + char *fname = pg_malloc(fnamelen); snprintf(fname, fnamelen, "%s%s", path, ".gz"); fp = cfopen(fname, mode, 1); @@ -525,10 +508,7 @@ cfopen_write(const char *path, const char *mode, int compression) { #ifdef HAVE_LIBZ int fnamelen = strlen(path) + 4; - char *fname = malloc(fnamelen); - - if (fname == NULL) - die_horribly(NULL, modulename, "Out of memory\n"); + char *fname = pg_malloc(fnamelen); snprintf(fname, fnamelen, "%s%s", path, ".gz"); fp = cfopen(fname, mode, 1); @@ -548,10 +528,7 @@ cfopen_write(const char *path, const char *mode, int compression) cfp * cfopen(const char *path, const char *mode, int compression) { - cfp *fp = malloc(sizeof(cfp)); - - if (fp == NULL) - die_horribly(NULL, modulename, "Out of memory\n"); + cfp *fp = pg_malloc(sizeof(cfp)); if (compression != 0) { |