1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-06 07:49:08 +03:00

Modify pg_dump to use error-free memory allocation macros. This avoids

ignoring errors and call-site error checking.
This commit is contained in:
Bruce Momjian
2011-11-25 15:40:51 -05:00
parent 35e27226b6
commit 3c0afde11a
18 changed files with 1357 additions and 1361 deletions

View File

@@ -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)
{