pg_dump vs malloc
I came across a situation today with a pretty bad crash of pg_dump,
due to not checking the return code from malloc(). When looking
through the code, it seems there are a *lot* of places in pg_dump that
doesn't check the malloc return code.
But we do have a pg_malloc() function in there - but from what I can
tell it's only used very sparsely?
Shouldn't we be using that one more or less everywhere, or even #define it?
Or am I missing something in the code here?
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
Magnus Hagander <magnus@hagander.net> writes:
I came across a situation today with a pretty bad crash of pg_dump,
due to not checking the return code from malloc(). When looking
through the code, it seems there are a *lot* of places in pg_dump that
doesn't check the malloc return code.
But we do have a pg_malloc() function in there - but from what I can
tell it's only used very sparsely?
Shouldn't we be using that one more or less everywhere
Yup. Have at it.
regards, tom lane
On Fri, Jun 10, 2011 at 21:07, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Magnus Hagander <magnus@hagander.net> writes:
I came across a situation today with a pretty bad crash of pg_dump,
due to not checking the return code from malloc(). When looking
through the code, it seems there are a *lot* of places in pg_dump that
doesn't check the malloc return code.But we do have a pg_malloc() function in there - but from what I can
tell it's only used very sparsely?Shouldn't we be using that one more or less everywhere
Yup. Have at it.
Something along the line of this?
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
Attachments:
pg_dump_malloc.patchtext/x-patch; charset=US-ASCII; name=pg_dump_malloc.patchDownload
diff --git a/src/bin/pg_dump/Makefile b/src/bin/pg_dump/Makefile
index 8410af1..0737505 100644
--- a/src/bin/pg_dump/Makefile
+++ b/src/bin/pg_dump/Makefile
@@ -20,7 +20,7 @@ override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \
pg_backup_files.o pg_backup_null.o pg_backup_tar.o \
- pg_backup_directory.o dumputils.o compress_io.o $(WIN32RES)
+ pg_backup_directory.o pg_dump_alloc.o dumputils.o compress_io.o $(WIN32RES)
KEYWRDOBJS = keywords.o kwlookup.o
@@ -35,8 +35,8 @@ pg_dump: pg_dump.o common.o pg_dump_sort.o $(OBJS) $(KEYWRDOBJS) | submake-libpq
pg_restore: pg_restore.o $(OBJS) $(KEYWRDOBJS) | submake-libpq submake-libpgport
$(CC) $(CFLAGS) pg_restore.o $(KEYWRDOBJS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
-pg_dumpall: pg_dumpall.o dumputils.o $(KEYWRDOBJS) | submake-libpq submake-libpgport
- $(CC) $(CFLAGS) pg_dumpall.o dumputils.o $(KEYWRDOBJS) $(WIN32RES) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+pg_dumpall: pg_dumpall.o dumputils.o pg_dump_alloc.o $(KEYWRDOBJS) | submake-libpq submake-libpgport
+ $(CC) $(CFLAGS) pg_dumpall.o dumputils.o pg_dump_alloc.o $(KEYWRDOBJS) $(WIN32RES) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
install: all installdirs
$(INSTALL_PROGRAM) pg_dump$(X) '$(DESTDIR)$(bindir)'/pg_dump$(X)
diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c
index a631f64..b194f24 100644
--- a/src/bin/pg_dump/common.c
+++ b/src/bin/pg_dump/common.c
@@ -980,57 +980,3 @@ simple_string_list_member(SimpleStringList *list, const char *val)
}
-/*
- * Safer versions of some standard C library functions. If an
- * out-of-memory condition occurs, these functions will bail out
- * safely; therefore, their return value is guaranteed to be non-NULL.
- *
- * XXX need to refactor things so that these can be in a file that can be
- * shared by pg_dumpall and pg_restore as well as pg_dump.
- */
-
-char *
-pg_strdup(const char *string)
-{
- char *tmp;
-
- if (!string)
- exit_horribly(NULL, NULL, "cannot duplicate null pointer\n");
- tmp = strdup(string);
- if (!tmp)
- exit_horribly(NULL, NULL, "out of memory\n");
- return tmp;
-}
-
-void *
-pg_malloc(size_t size)
-{
- void *tmp;
-
- tmp = malloc(size);
- if (!tmp)
- exit_horribly(NULL, NULL, "out of memory\n");
- return tmp;
-}
-
-void *
-pg_calloc(size_t nmemb, size_t size)
-{
- void *tmp;
-
- tmp = calloc(nmemb, size);
- if (!tmp)
- exit_horribly(NULL, NULL, "out of memory\n");
- return tmp;
-}
-
-void *
-pg_realloc(void *ptr, size_t size)
-{
- void *tmp;
-
- tmp = realloc(ptr, size);
- if (!tmp)
- exit_horribly(NULL, NULL, "out of memory\n");
- return tmp;
-}
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 0e1037c..78b5e93 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -735,8 +735,6 @@ ArchiveEntry(Archive *AHX,
TocEntry *newToc;
newToc = (TocEntry *) calloc(1, sizeof(TocEntry));
- if (!newToc)
- die_horribly(AH, modulename, "out of memory\n");
AH->tocCount++;
if (dumpId > AH->maxDumpId)
@@ -1131,8 +1129,6 @@ archprintf(Archive *AH, const char *fmt,...)
free(p);
bSize *= 2;
p = (char *) malloc(bSize);
- if (p == NULL)
- exit_horribly(AH, modulename, "out of memory\n");
va_start(ap, fmt);
cnt = vsnprintf(p, bSize, fmt, ap);
va_end(ap);
@@ -1266,8 +1262,6 @@ ahprintf(ArchiveHandle *AH, const char *fmt,...)
free(p);
bSize *= 2;
p = (char *) malloc(bSize);
- if (p == NULL)
- die_horribly(AH, modulename, "out of memory\n");
va_start(ap, fmt);
cnt = vsnprintf(p, bSize, fmt, ap);
va_end(ap);
@@ -1736,8 +1730,6 @@ ReadStr(ArchiveHandle *AH)
else
{
buf = (char *) malloc(l + 1);
- if (!buf)
- die_horribly(AH, modulename, "out of memory\n");
if ((*AH->ReadBufPtr) (AH, (void *) buf, l) != l)
die_horribly(AH, modulename, "unexpected end of file\n");
@@ -1930,8 +1922,6 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
#endif
AH = (ArchiveHandle *) calloc(1, sizeof(ArchiveHandle));
- if (!AH)
- die_horribly(AH, modulename, "out of memory\n");
/* AH->debugLevel = 100; */
@@ -1976,8 +1966,6 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
AH->currWithOids = -1; /* force SET */
AH->toc = (TocEntry *) calloc(1, sizeof(TocEntry));
- if (!AH->toc)
- die_horribly(AH, modulename, "out of memory\n");
AH->toc->next = AH->toc;
AH->toc->prev = AH->toc;
@@ -4195,8 +4183,6 @@ CloneArchive(ArchiveHandle *AH)
/* Make a "flat" copy */
clone = (ArchiveHandle *) malloc(sizeof(ArchiveHandle));
- if (clone == NULL)
- die_horribly(AH, modulename, "out of memory\n");
memcpy(clone, AH, sizeof(ArchiveHandle));
/* Handle format-independent fields */
diff --git a/src/bin/pg_dump/pg_backup_custom.c b/src/bin/pg_dump/pg_backup_custom.c
index 01d5e37..e1635ae 100644
--- a/src/bin/pg_dump/pg_backup_custom.c
+++ b/src/bin/pg_dump/pg_backup_custom.c
@@ -128,15 +128,11 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
/* Set up a private area. */
ctx = (lclContext *) calloc(1, sizeof(lclContext));
- if (ctx == NULL)
- die_horribly(AH, modulename, "out of memory\n");
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");
ctx->filePos = 0;
@@ -771,8 +767,6 @@ _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");
memcpy(AH->formatData, ctx, sizeof(lclContext));
ctx = (lclContext *) AH->formatData;
@@ -898,8 +892,6 @@ _CustomReadFunc(ArchiveHandle *AH, char **buf, size_t *buflen)
{
free(*buf);
*buf = (char *) malloc(blkLen);
- if (!(*buf))
- die_horribly(AH, modulename, "out of memory\n");
*buflen = blkLen;
}
diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c
index cc3882c..67deaa7 100644
--- a/src/bin/pg_dump/pg_backup_db.c
+++ b/src/bin/pg_dump/pg_backup_db.c
@@ -160,9 +160,6 @@ _connectDB(ArchiveHandle *AH, const char *reqdb, const char *requser)
const char **keywords = malloc(PARAMS_ARRAY_SIZE * sizeof(*keywords));
const char **values = malloc(PARAMS_ARRAY_SIZE * sizeof(*values));
- if (!keywords || !values)
- die_horribly(AH, modulename, "out of memory\n");
-
keywords[0] = "host";
values[0] = PQhost(AH->connection);
keywords[1] = "port";
@@ -267,9 +264,6 @@ ConnectDatabase(Archive *AHX,
const char **keywords = malloc(PARAMS_ARRAY_SIZE * sizeof(*keywords));
const char **values = malloc(PARAMS_ARRAY_SIZE * sizeof(*values));
- if (!keywords || !values)
- die_horribly(AH, modulename, "out of memory\n");
-
keywords[0] = "host";
values[0] = pghost;
keywords[1] = "port";
diff --git a/src/bin/pg_dump/pg_backup_directory.c b/src/bin/pg_dump/pg_backup_directory.c
index 111c3e8..b0bdf5f 100644
--- a/src/bin/pg_dump/pg_backup_directory.c
+++ b/src/bin/pg_dump/pg_backup_directory.c
@@ -127,8 +127,6 @@ InitArchiveFmt_Directory(ArchiveHandle *AH)
/* Set up our private context */
ctx = (lclContext *) calloc(1, sizeof(lclContext));
- if (ctx == NULL)
- die_horribly(AH, modulename, "out of memory\n");
AH->formatData = (void *) ctx;
ctx->dataFH = NULL;
@@ -137,8 +135,6 @@ InitArchiveFmt_Directory(ArchiveHandle *AH)
/* 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");
/*
* Now open the TOC file
@@ -198,8 +194,6 @@ _ArchiveEntry(ArchiveHandle *AH, TocEntry *te)
char fn[MAXPGPATH];
tctx = (lclTocEntry *) calloc(1, sizeof(lclTocEntry));
- if (!tctx)
- die_horribly(AH, modulename, "out of memory\n");
if (te->dataDumper)
{
snprintf(fn, MAXPGPATH, "%d.dat", te->dumpId);
@@ -249,8 +243,6 @@ _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
if (tctx == NULL)
{
tctx = (lclTocEntry *) calloc(1, sizeof(lclTocEntry));
- if (!tctx)
- die_horribly(AH, modulename, "out of memory\n");
te->formatData = (void *) tctx;
}
@@ -357,8 +349,6 @@ _PrintFileData(ArchiveHandle *AH, char *filename, RestoreOptions *ropt)
filename, strerror(errno));
buf = malloc(ZLIB_OUT_SIZE);
- if (buf == NULL)
- die_horribly(NULL, modulename, "out of memory\n");
buflen = ZLIB_OUT_SIZE;
while ((cnt = cfread(buf, buflen, cfp)))
diff --git a/src/bin/pg_dump/pg_backup_files.c b/src/bin/pg_dump/pg_backup_files.c
index abc93b1..55dfab3 100644
--- a/src/bin/pg_dump/pg_backup_files.c
+++ b/src/bin/pg_dump/pg_backup_files.c
@@ -110,8 +110,6 @@ InitArchiveFmt_Files(ArchiveHandle *AH)
/* 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");
/*
* Now open the TOC file
diff --git a/src/bin/pg_dump/pg_backup_null.c b/src/bin/pg_dump/pg_backup_null.c
index bf1e6e6..1e86aaa 100644
--- a/src/bin/pg_dump/pg_backup_null.c
+++ b/src/bin/pg_dump/pg_backup_null.c
@@ -68,8 +68,6 @@ InitArchiveFmt_Null(ArchiveHandle *AH)
/* Initialize LO buffering */
AH->lo_buf_size = LOBBUFSIZE;
AH->lo_buf = (void *) malloc(LOBBUFSIZE);
- if (AH->lo_buf == NULL)
- die_horribly(AH, NULL, "out of memory\n");
/*
* Now prevent reading...
diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c
index 041f9f9..3c9e01d 100644
--- a/src/bin/pg_dump/pg_backup_tar.c
+++ b/src/bin/pg_dump/pg_backup_tar.c
@@ -167,8 +167,6 @@ InitArchiveFmt_Tar(ArchiveHandle *AH)
/* 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");
/*
* Now open the tar file, and load the TOC if we're in read mode.
@@ -1011,8 +1009,6 @@ tarPrintf(ArchiveHandle *AH, TAR_MEMBER *th, const char *fmt,...)
free(p);
bSize *= 2;
p = (char *) malloc(bSize);
- if (p == NULL)
- die_horribly(AH, modulename, "out of memory\n");
va_start(ap, fmt);
cnt = vsnprintf(p, bSize, fmt, ap);
va_end(ap);
diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h
index c95614b..000e8e3 100644
--- a/src/bin/pg_dump/pg_dump.h
+++ b/src/bin/pg_dump/pg_dump.h
@@ -520,10 +520,23 @@ extern void simple_string_list_append(SimpleStringList *list, const char *val);
extern bool simple_oid_list_member(SimpleOidList *list, Oid val);
extern bool simple_string_list_member(SimpleStringList *list, const char *val);
+/*
+ * Redefinitions of the memory allocation functions that call
+ * die_horribly() when they fail instead of returning NULL.
+ */
extern char *pg_strdup(const char *string);
extern void *pg_malloc(size_t size);
extern void *pg_calloc(size_t nmemb, size_t size);
extern void *pg_realloc(void *ptr, size_t size);
+#ifndef PG_DUMP_NO_ALLOC_REDEFINE
+#ifdef strdup
+#undef strdup
+#endif
+#define strdup(x) pg_strdup(x)
+#define malloc(x) pg_malloc(x)
+#define calloc(x,y) pg_calloc(x, y)
+#define realloc(x,y) pg_realloc(x, y)
+#endif
extern void check_conn_and_db(void);
extern void exit_nicely(void);
diff --git a/src/bin/pg_dump/pg_dump_alloc.c b/src/bin/pg_dump/pg_dump_alloc.c
new file mode 100644
index 0000000..7b252a7
--- /dev/null
+++ b/src/bin/pg_dump/pg_dump_alloc.c
@@ -0,0 +1,54 @@
+#define PG_DUMP_NO_ALLOC_REDEFINE
+#include "pg_backup.h"
+
+/*
+ * Safer versions of some standard C library functions. If an
+ * out-of-memory condition occurs, these functions will bail out
+ * safely; therefore, their return value is guaranteed to be non-NULL.
+ */
+
+char *
+pg_strdup(const char *string)
+{
+ char *tmp;
+
+ if (!string)
+ exit_horribly(NULL, NULL, "cannot duplicate null pointer\n");
+ tmp = strdup(string);
+ if (!tmp)
+ exit_horribly(NULL, NULL, "out of memory\n");
+ return tmp;
+}
+
+void *
+pg_malloc(size_t size)
+{
+ void *tmp;
+
+ tmp = malloc(size);
+ if (!tmp)
+ exit_horribly(NULL, NULL, "out of memory\n");
+ return tmp;
+}
+
+void *
+pg_calloc(size_t nmemb, size_t size)
+{
+ void *tmp;
+
+ tmp = calloc(nmemb, size);
+ if (!tmp)
+ exit_horribly(NULL, NULL, "out of memory\n");
+ return tmp;
+}
+
+void *
+pg_realloc(void *ptr, size_t size)
+{
+ void *tmp;
+
+ tmp = realloc(ptr, size);
+ if (!tmp)
+ exit_horribly(NULL, NULL, "out of memory\n");
+ return tmp;
+}
diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c
index 963f734..09acb51 100644
--- a/src/bin/pg_dump/pg_dump_sort.c
+++ b/src/bin/pg_dump/pg_dump_sort.c
@@ -228,8 +228,6 @@ sortDumpableObjects(DumpableObject **objs, int numObjs)
return;
ordering = (DumpableObject **) malloc(numObjs * sizeof(DumpableObject *));
- if (ordering == NULL)
- exit_horribly(NULL, modulename, "out of memory\n");
while (!TopoSort(objs, numObjs, ordering, &nOrdering))
findDependencyLoops(ordering, nOrdering, numObjs);
@@ -302,8 +300,6 @@ TopoSort(DumpableObject **objs,
/* Create workspace for the above-described heap */
pendingHeap = (int *) malloc(numObjs * sizeof(int));
- if (pendingHeap == NULL)
- exit_horribly(NULL, modulename, "out of memory\n");
/*
* Scan the constraints, and for each item in the input, generate a count
@@ -313,12 +309,8 @@ TopoSort(DumpableObject **objs,
* dumpId j.
*/
beforeConstraints = (int *) malloc((maxDumpId + 1) * sizeof(int));
- if (beforeConstraints == NULL)
- exit_horribly(NULL, modulename, "out of memory\n");
memset(beforeConstraints, 0, (maxDumpId + 1) * sizeof(int));
idMap = (int *) malloc((maxDumpId + 1) * sizeof(int));
- if (idMap == NULL)
- exit_horribly(NULL, modulename, "out of memory\n");
for (i = 0; i < numObjs; i++)
{
obj = objs[i];
@@ -517,8 +509,6 @@ findDependencyLoops(DumpableObject **objs, int nObjs, int totObjs)
int i;
workspace = (DumpableObject **) malloc(totObjs * sizeof(DumpableObject *));
- if (workspace == NULL)
- exit_horribly(NULL, modulename, "out of memory\n");
initiallen = 0;
fixedloop = false;
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index b3ad2ea..a47bf63 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -1646,12 +1646,6 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
const char **keywords = malloc(PARAMS_ARRAY_SIZE * sizeof(*keywords));
const char **values = malloc(PARAMS_ARRAY_SIZE * sizeof(*values));
- if (!keywords || !values)
- {
- fprintf(stderr, _("%s: out of memory\n"), progname);
- exit(1);
- }
-
keywords[0] = "host";
values[0] = pghost;
keywords[1] = "port";
@@ -1866,3 +1860,21 @@ doShellQuoting(PQExpBuffer buf, const char *str)
appendPQExpBufferChar(buf, '"');
#endif /* WIN32 */
}
+
+/*
+ * exit_horribly() is called from the redefined memory allocation
+ * routines if we run out of memory.
+ */
+void
+exit_horribly(Archive *AH, const char *modulename, const char *fmt,...)
+{
+ va_list ap;
+
+ fprintf(stderr, "%s: ", progname);
+
+ va_start(ap, fmt);
+ vfprintf(stderr, _(fmt), ap);
+ va_end(ap);
+
+ exit(1);
+}
Magnus Hagander <magnus@hagander.net> writes:
Something along the line of this?
I think this is a seriously, seriously bad idea:
+#define strdup(x) pg_strdup(x) +#define malloc(x) pg_malloc(x) +#define calloc(x,y) pg_calloc(x, y) +#define realloc(x,y) pg_realloc(x, y)
as it will render the code unreadable to people expecting the normal
behavior of these fundamental functions; not to mention break any
call sites that have some other means of dealing with an alloc failure
besides going belly-up. Please take the trouble to do
s/malloc/pg_malloc/g and so on, instead.
regards, tom lane
On 22 June 2011 16:25, Magnus Hagander <magnus@hagander.net> wrote:
Something along the line of this?
IMHO the redefinition of malloc() looks a bit hairy...can't you just
make the callers use the functions directly?
--
Peter Geoghegan http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training and Services
On Wed, Jun 22, 2011 at 17:48, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Magnus Hagander <magnus@hagander.net> writes:
Something along the line of this?
I think this is a seriously, seriously bad idea:
+#define strdup(x) pg_strdup(x) +#define malloc(x) pg_malloc(x) +#define calloc(x,y) pg_calloc(x, y) +#define realloc(x,y) pg_realloc(x, y)as it will render the code unreadable to people expecting the normal
behavior of these fundamental functions; not to mention break any
call sites that have some other means of dealing with an alloc failure
besides going belly-up. Please take the trouble to do
s/malloc/pg_malloc/g and so on, instead.
Ok, I'll try that approach. This seemed like a "nicer" approach, but I
think once written out, i agree with your arguments :-)
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
Excerpts from Magnus Hagander's message of mié jun 22 11:25:43 -0400 2011:
On Fri, Jun 10, 2011 at 21:07, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Magnus Hagander <magnus@hagander.net> writes:
I came across a situation today with a pretty bad crash of pg_dump,
due to not checking the return code from malloc(). When looking
through the code, it seems there are a *lot* of places in pg_dump that
doesn't check the malloc return code.But we do have a pg_malloc() function in there - but from what I can
tell it's only used very sparsely?Shouldn't we be using that one more or less everywhere
Yup. Have at it.
Something along the line of this?
Huh, do you really need a new file for the four new functions? What's
wrong with common.c?
--
Álvaro Herrera <alvherre@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Magnus Hagander wrote:
On Wed, Jun 22, 2011 at 17:48, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Magnus Hagander <magnus@hagander.net> writes:
Something along the line of this?
I think this is a seriously, seriously bad idea:
+#define strdup(x) pg_strdup(x) +#define malloc(x) pg_malloc(x) +#define calloc(x,y) pg_calloc(x, y) +#define realloc(x,y) pg_realloc(x, y)as it will render the code unreadable to people expecting the normal
behavior of these fundamental functions; not to mention break any
call sites that have some other means of dealing with an alloc failure
besides going belly-up. ?Please take the trouble to do
s/malloc/pg_malloc/g and so on, instead.Ok, I'll try that approach. This seemed like a "nicer" approach, but I
think once written out, i agree with your arguments :-)
Where are we on this?
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
On Fri, Oct 14, 2011 at 21:11, Bruce Momjian <bruce@momjian.us> wrote:
Magnus Hagander wrote:
On Wed, Jun 22, 2011 at 17:48, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Magnus Hagander <magnus@hagander.net> writes:
Something along the line of this?
I think this is a seriously, seriously bad idea:
+#define strdup(x) pg_strdup(x) +#define malloc(x) pg_malloc(x) +#define calloc(x,y) pg_calloc(x, y) +#define realloc(x,y) pg_realloc(x, y)as it will render the code unreadable to people expecting the normal
behavior of these fundamental functions; not to mention break any
call sites that have some other means of dealing with an alloc failure
besides going belly-up. ?Please take the trouble to do
s/malloc/pg_malloc/g and so on, instead.Ok, I'll try that approach. This seemed like a "nicer" approach, but I
think once written out, i agree with your arguments :-)Where are we on this?
It's still sitting on my personal TODO list, just not with a really
high priority.
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
Alvaro Herrera wrote:
Excerpts from Magnus Hagander's message of mi�� jun 22 11:25:43 -0400 2011:
On Fri, Jun 10, 2011 at 21:07, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Magnus Hagander <magnus@hagander.net> writes:
I came across a situation today with a pretty bad crash of pg_dump,
due to not checking the return code from malloc(). When looking
through the code, it seems there are a *lot* of places in pg_dump that
doesn't check the malloc return code.But we do have a pg_malloc() function in there - but from what I can
tell it's only used very sparsely?Shouldn't we be using that one more or less everywhere
Yup. ��Have at it.
Something along the line of this?
Huh, do you really need a new file for the four new functions? What's
wrong with common.c?
I developed the attached patch to handle this. I moved the catalog code
from common.c into dumpcatalog.c, so there are just memory routines now
in common.c. I created new memory routines in pg_dumpall.c because
there is no AH structure in pg_dumpall.c. I then modified all the calls
to use the new routines, and removed the NULL return checks that were no
longer necessary.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
Attachments:
/rtmp/pg_dumptext/x-diffDownload
diff --git a/src/bin/pg_dump/Makefile b/src/bin/pg_dump/Makefile
new file mode 100644
index 8410af1..9d13bec
*** a/src/bin/pg_dump/Makefile
--- b/src/bin/pg_dump/Makefile
*************** override CPPFLAGS := -I$(libpq_srcdir) $
*** 20,26 ****
OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \
pg_backup_files.o pg_backup_null.o pg_backup_tar.o \
! pg_backup_directory.o dumputils.o compress_io.o $(WIN32RES)
KEYWRDOBJS = keywords.o kwlookup.o
--- 20,26 ----
OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \
pg_backup_files.o pg_backup_null.o pg_backup_tar.o \
! pg_backup_directory.o common.o dumputils.o compress_io.o $(WIN32RES)
KEYWRDOBJS = keywords.o kwlookup.o
*************** kwlookup.c: % : $(top_srcdir)/src/backen
*** 29,36 ****
all: pg_dump pg_restore pg_dumpall
! pg_dump: pg_dump.o common.o pg_dump_sort.o $(OBJS) $(KEYWRDOBJS) | submake-libpq submake-libpgport
! $(CC) $(CFLAGS) pg_dump.o common.o pg_dump_sort.o $(KEYWRDOBJS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
pg_restore: pg_restore.o $(OBJS) $(KEYWRDOBJS) | submake-libpq submake-libpgport
$(CC) $(CFLAGS) pg_restore.o $(KEYWRDOBJS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
--- 29,36 ----
all: pg_dump pg_restore pg_dumpall
! pg_dump: pg_dump.o dumpcatalog.o pg_dump_sort.o $(OBJS) $(KEYWRDOBJS) | submake-libpq submake-libpgport
! $(CC) $(CFLAGS) pg_dump.o dumpcatalog.o pg_dump_sort.o $(KEYWRDOBJS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
pg_restore: pg_restore.o $(OBJS) $(KEYWRDOBJS) | submake-libpq submake-libpgport
$(CC) $(CFLAGS) pg_restore.o $(KEYWRDOBJS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
*************** uninstall:
*** 50,53 ****
rm -f $(addprefix '$(DESTDIR)$(bindir)'/, pg_dump$(X) pg_restore$(X) pg_dumpall$(X))
clean distclean maintainer-clean:
! rm -f pg_dump$(X) pg_restore$(X) pg_dumpall$(X) $(OBJS) pg_dump.o common.o pg_dump_sort.o pg_restore.o pg_dumpall.o kwlookup.c $(KEYWRDOBJS)
--- 50,53 ----
rm -f $(addprefix '$(DESTDIR)$(bindir)'/, pg_dump$(X) pg_restore$(X) pg_dumpall$(X))
clean distclean maintainer-clean:
! rm -f pg_dump$(X) pg_restore$(X) pg_dumpall$(X) $(OBJS) pg_dump.o dumpcatalog.o pg_dump_sort.o pg_restore.o pg_dumpall.o kwlookup.c $(KEYWRDOBJS)
diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c
new file mode 100644
index bd81a2c..1a3f4cb
*** a/src/bin/pg_dump/common.c
--- b/src/bin/pg_dump/common.c
***************
*** 1,10 ****
/*-------------------------------------------------------------------------
*
* common.c
! * common routines between pg_dump and pg4_dump
! *
! * Since pg4_dump is long-dead code, there is no longer any useful distinction
! * between this file and pg_dump.c.
*
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
--- 1,8 ----
/*-------------------------------------------------------------------------
*
* common.c
! * common routines between pg_dump and pg_restore (but not pg_dumpall
! * because there is no failure location to report).
*
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
***************
*** 16,992 ****
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
#include <ctype.h>
- #include "catalog/pg_class.h"
-
- #include "pg_backup_archiver.h"
-
-
- /*
- * Variables for mapping DumpId to DumpableObject
- */
- static DumpableObject **dumpIdMap = NULL;
- static int allocedDumpIds = 0;
- static DumpId lastDumpId = 0;
-
- /*
- * Variables for mapping CatalogId to DumpableObject
- */
- static bool catalogIdMapValid = false;
- static DumpableObject **catalogIdMap = NULL;
- static int numCatalogIds = 0;
-
- /*
- * These variables are static to avoid the notational cruft of having to pass
- * them into findTableByOid() and friends. For each of these arrays, we
- * build a sorted-by-OID index array immediately after it's built, and then
- * we use binary search in findTableByOid() and friends. (qsort'ing the base
- * arrays themselves would be simpler, but it doesn't work because pg_dump.c
- * may have already established pointers between items.)
- */
- static TableInfo *tblinfo;
- static TypeInfo *typinfo;
- static FuncInfo *funinfo;
- static OprInfo *oprinfo;
- static int numTables;
- static int numTypes;
- static int numFuncs;
- static int numOperators;
- static int numCollations;
- static DumpableObject **tblinfoindex;
- static DumpableObject **typinfoindex;
- static DumpableObject **funinfoindex;
- static DumpableObject **oprinfoindex;
- static DumpableObject **collinfoindex;
-
-
- static void flagInhTables(TableInfo *tbinfo, int numTables,
- InhInfo *inhinfo, int numInherits);
- static void flagInhAttrs(TableInfo *tblinfo, int numTables);
- static DumpableObject **buildIndexArray(void *objArray, int numObjs,
- Size objSize);
- static int DOCatalogIdCompare(const void *p1, const void *p2);
- static void findParentsByOid(TableInfo *self,
- InhInfo *inhinfo, int numInherits);
- static int strInArray(const char *pattern, char **arr, int arr_size);
-
-
- /*
- * getSchemaData
- * Collect information about all potentially dumpable objects
- */
- TableInfo *
- getSchemaData(int *numTablesPtr)
- {
- ExtensionInfo *extinfo;
- InhInfo *inhinfo;
- CollInfo *collinfo;
- int numNamespaces;
- int numExtensions;
- int numAggregates;
- int numInherits;
- int numRules;
- int numProcLangs;
- int numCasts;
- int numOpclasses;
- int numOpfamilies;
- int numConversions;
- int numTSParsers;
- int numTSTemplates;
- int numTSDicts;
- int numTSConfigs;
- int numForeignDataWrappers;
- int numForeignServers;
- int numDefaultACLs;
-
- if (g_verbose)
- write_msg(NULL, "reading schemas\n");
- getNamespaces(&numNamespaces);
-
- /*
- * getTables should be done as soon as possible, so as to minimize the
- * window between starting our transaction and acquiring per-table locks.
- * However, we have to do getNamespaces first because the tables get
- * linked to their containing namespaces during getTables.
- */
- if (g_verbose)
- write_msg(NULL, "reading user-defined tables\n");
- tblinfo = getTables(&numTables);
- tblinfoindex = buildIndexArray(tblinfo, numTables, sizeof(TableInfo));
-
- if (g_verbose)
- write_msg(NULL, "reading extensions\n");
- extinfo = getExtensions(&numExtensions);
-
- if (g_verbose)
- write_msg(NULL, "reading user-defined functions\n");
- funinfo = getFuncs(&numFuncs);
- funinfoindex = buildIndexArray(funinfo, numFuncs, sizeof(FuncInfo));
-
- /* this must be after getTables and getFuncs */
- if (g_verbose)
- write_msg(NULL, "reading user-defined types\n");
- typinfo = getTypes(&numTypes);
- typinfoindex = buildIndexArray(typinfo, numTypes, sizeof(TypeInfo));
-
- /* this must be after getFuncs, too */
- if (g_verbose)
- write_msg(NULL, "reading procedural languages\n");
- getProcLangs(&numProcLangs);
-
- if (g_verbose)
- write_msg(NULL, "reading user-defined aggregate functions\n");
- getAggregates(&numAggregates);
-
- if (g_verbose)
- write_msg(NULL, "reading user-defined operators\n");
- oprinfo = getOperators(&numOperators);
- oprinfoindex = buildIndexArray(oprinfo, numOperators, sizeof(OprInfo));
-
- if (g_verbose)
- write_msg(NULL, "reading user-defined operator classes\n");
- getOpclasses(&numOpclasses);
-
- if (g_verbose)
- write_msg(NULL, "reading user-defined operator families\n");
- getOpfamilies(&numOpfamilies);
-
- if (g_verbose)
- write_msg(NULL, "reading user-defined text search parsers\n");
- getTSParsers(&numTSParsers);
-
- if (g_verbose)
- write_msg(NULL, "reading user-defined text search templates\n");
- getTSTemplates(&numTSTemplates);
-
- if (g_verbose)
- write_msg(NULL, "reading user-defined text search dictionaries\n");
- getTSDictionaries(&numTSDicts);
-
- if (g_verbose)
- write_msg(NULL, "reading user-defined text search configurations\n");
- getTSConfigurations(&numTSConfigs);
-
- if (g_verbose)
- write_msg(NULL, "reading user-defined foreign-data wrappers\n");
- getForeignDataWrappers(&numForeignDataWrappers);
-
- if (g_verbose)
- write_msg(NULL, "reading user-defined foreign servers\n");
- getForeignServers(&numForeignServers);
-
- if (g_verbose)
- write_msg(NULL, "reading default privileges\n");
- getDefaultACLs(&numDefaultACLs);
-
- if (g_verbose)
- write_msg(NULL, "reading user-defined collations\n");
- collinfo = getCollations(&numCollations);
- collinfoindex = buildIndexArray(collinfo, numCollations, sizeof(CollInfo));
-
- if (g_verbose)
- write_msg(NULL, "reading user-defined conversions\n");
- getConversions(&numConversions);
-
- if (g_verbose)
- write_msg(NULL, "reading type casts\n");
- getCasts(&numCasts);
-
- if (g_verbose)
- write_msg(NULL, "reading table inheritance information\n");
- inhinfo = getInherits(&numInherits);
-
- if (g_verbose)
- write_msg(NULL, "reading rewrite rules\n");
- getRules(&numRules);
-
- /*
- * Identify extension member objects and mark them as not to be dumped.
- * This must happen after reading all objects that can be direct members
- * of extensions, but before we begin to process table subsidiary objects.
- */
- if (g_verbose)
- write_msg(NULL, "finding extension members\n");
- getExtensionMembership(extinfo, numExtensions);
-
- /* Link tables to parents, mark parents of target tables interesting */
- if (g_verbose)
- write_msg(NULL, "finding inheritance relationships\n");
- flagInhTables(tblinfo, numTables, inhinfo, numInherits);
-
- if (g_verbose)
- write_msg(NULL, "reading column info for interesting tables\n");
- getTableAttrs(tblinfo, numTables);
-
- if (g_verbose)
- write_msg(NULL, "flagging inherited columns in subtables\n");
- flagInhAttrs(tblinfo, numTables);
-
- if (g_verbose)
- write_msg(NULL, "reading indexes\n");
- getIndexes(tblinfo, numTables);
-
- if (g_verbose)
- write_msg(NULL, "reading constraints\n");
- getConstraints(tblinfo, numTables);
-
- if (g_verbose)
- write_msg(NULL, "reading triggers\n");
- getTriggers(tblinfo, numTables);
-
- *numTablesPtr = numTables;
- return tblinfo;
- }
-
- /* flagInhTables -
- * Fill in parent link fields of every target table, and mark
- * parents of target tables as interesting
- *
- * Note that only direct ancestors of targets are marked interesting.
- * This is sufficient; we don't much care whether they inherited their
- * attributes or not.
- *
- * modifies tblinfo
- */
- static void
- flagInhTables(TableInfo *tblinfo, int numTables,
- InhInfo *inhinfo, int numInherits)
- {
- int i,
- j;
- int numParents;
- TableInfo **parents;
-
- for (i = 0; i < numTables; i++)
- {
- /* Sequences and views never have parents */
- if (tblinfo[i].relkind == RELKIND_SEQUENCE ||
- tblinfo[i].relkind == RELKIND_VIEW)
- continue;
-
- /* Don't bother computing anything for non-target tables, either */
- if (!tblinfo[i].dobj.dump)
- continue;
-
- /* Find all the immediate parent tables */
- findParentsByOid(&tblinfo[i], inhinfo, numInherits);
-
- /* Mark the parents as interesting for getTableAttrs */
- numParents = tblinfo[i].numParents;
- parents = tblinfo[i].parents;
- for (j = 0; j < numParents; j++)
- parents[j]->interesting = true;
- }
- }
-
- /* flagInhAttrs -
- * for each dumpable table in tblinfo, flag its inherited attributes
- * so when we dump the table out, we don't dump out the inherited attributes
- *
- * modifies tblinfo
- */
- static void
- flagInhAttrs(TableInfo *tblinfo, int numTables)
- {
- int i,
- j,
- k;
-
- for (i = 0; i < numTables; i++)
- {
- TableInfo *tbinfo = &(tblinfo[i]);
- int numParents;
- TableInfo **parents;
- TableInfo *parent;
-
- /* Sequences and views never have parents */
- if (tbinfo->relkind == RELKIND_SEQUENCE ||
- tbinfo->relkind == RELKIND_VIEW)
- continue;
-
- /* Don't bother computing anything for non-target tables, either */
- if (!tbinfo->dobj.dump)
- continue;
-
- numParents = tbinfo->numParents;
- parents = tbinfo->parents;
-
- if (numParents == 0)
- continue; /* nothing to see here, move along */
-
- /*----------------------------------------------------------------
- * For each attr, check the parent info: if no parent has an attr
- * with the same name, then it's not inherited. If there *is* an
- * attr with the same name, then only dump it if:
- *
- * - it is NOT NULL and zero parents are NOT NULL
- * OR
- * - it has a default value AND the default value does not match
- * all parent default values, or no parents specify a default.
- *
- * See discussion on -hackers around 2-Apr-2001.
- *----------------------------------------------------------------
- */
- for (j = 0; j < tbinfo->numatts; j++)
- {
- bool foundAttr; /* Attr was found in a parent */
- bool foundNotNull; /* Attr was NOT NULL in a parent */
- bool defaultsMatch; /* All non-empty defaults match */
- bool defaultsFound; /* Found a default in a parent */
- AttrDefInfo *attrDef;
-
- foundAttr = false;
- foundNotNull = false;
- defaultsMatch = true;
- defaultsFound = false;
-
- attrDef = tbinfo->attrdefs[j];
-
- for (k = 0; k < numParents; k++)
- {
- int inhAttrInd;
-
- parent = parents[k];
- inhAttrInd = strInArray(tbinfo->attnames[j],
- parent->attnames,
- parent->numatts);
-
- if (inhAttrInd != -1)
- {
- AttrDefInfo *inhDef = parent->attrdefs[inhAttrInd];
-
- foundAttr = true;
- foundNotNull |= parent->notnull[inhAttrInd];
- if (inhDef != NULL)
- {
- defaultsFound = true;
-
- /*
- * If any parent has a default and the child doesn't,
- * we have to emit an explicit DEFAULT NULL clause for
- * the child, else the parent's default will win.
- */
- if (attrDef == NULL)
- {
- attrDef = (AttrDefInfo *) malloc(sizeof(AttrDefInfo));
- attrDef->dobj.objType = DO_ATTRDEF;
- attrDef->dobj.catId.tableoid = 0;
- attrDef->dobj.catId.oid = 0;
- AssignDumpId(&attrDef->dobj);
- attrDef->adtable = tbinfo;
- attrDef->adnum = j + 1;
- attrDef->adef_expr = strdup("NULL");
-
- attrDef->dobj.name = strdup(tbinfo->dobj.name);
- attrDef->dobj.namespace = tbinfo->dobj.namespace;
-
- attrDef->dobj.dump = tbinfo->dobj.dump;
-
- attrDef->separate = false;
- addObjectDependency(&tbinfo->dobj,
- attrDef->dobj.dumpId);
-
- tbinfo->attrdefs[j] = attrDef;
- }
- if (strcmp(attrDef->adef_expr, inhDef->adef_expr) != 0)
- {
- defaultsMatch = false;
-
- /*
- * Whenever there is a non-matching parent
- * default, add a dependency to force the parent
- * default to be dumped first, in case the
- * defaults end up being dumped as separate
- * commands. Otherwise the parent default will
- * override the child's when it is applied.
- */
- addObjectDependency(&attrDef->dobj,
- inhDef->dobj.dumpId);
- }
- }
- }
- }
-
- /*
- * Based on the scan of the parents, decide if we can rely on the
- * inherited attr
- */
- if (foundAttr) /* Attr was inherited */
- {
- /* Set inherited flag by default */
- tbinfo->inhAttrs[j] = true;
- tbinfo->inhAttrDef[j] = true;
- tbinfo->inhNotNull[j] = true;
-
- /*
- * Clear it if attr had a default, but parents did not, or
- * mismatch
- */
- if ((attrDef != NULL) && (!defaultsFound || !defaultsMatch))
- {
- tbinfo->inhAttrs[j] = false;
- tbinfo->inhAttrDef[j] = false;
- }
-
- /*
- * Clear it if NOT NULL and none of the parents were NOT NULL
- */
- if (tbinfo->notnull[j] && !foundNotNull)
- {
- tbinfo->inhAttrs[j] = false;
- tbinfo->inhNotNull[j] = false;
- }
-
- /* Clear it if attr has local definition */
- if (tbinfo->attislocal[j])
- tbinfo->inhAttrs[j] = false;
- }
- }
- }
- }
-
- /*
- * AssignDumpId
- * Given a newly-created dumpable object, assign a dump ID,
- * and enter the object into the lookup table.
- *
- * The caller is expected to have filled in objType and catId,
- * but not any of the other standard fields of a DumpableObject.
- */
- void
- AssignDumpId(DumpableObject *dobj)
- {
- dobj->dumpId = ++lastDumpId;
- dobj->name = NULL; /* must be set later */
- dobj->namespace = NULL; /* may be set later */
- dobj->dump = true; /* default assumption */
- dobj->ext_member = false; /* default assumption */
- dobj->dependencies = NULL;
- dobj->nDeps = 0;
- dobj->allocDeps = 0;
-
- while (dobj->dumpId >= allocedDumpIds)
- {
- int newAlloc;
-
- if (allocedDumpIds <= 0)
- {
- newAlloc = 256;
- dumpIdMap = (DumpableObject **)
- pg_malloc(newAlloc * sizeof(DumpableObject *));
- }
- else
- {
- newAlloc = allocedDumpIds * 2;
- dumpIdMap = (DumpableObject **)
- pg_realloc(dumpIdMap, newAlloc * sizeof(DumpableObject *));
- }
- memset(dumpIdMap + allocedDumpIds, 0,
- (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
- allocedDumpIds = newAlloc;
- }
- dumpIdMap[dobj->dumpId] = dobj;
-
- /* mark catalogIdMap invalid, but don't rebuild it yet */
- catalogIdMapValid = false;
- }
-
- /*
- * Assign a DumpId that's not tied to a DumpableObject.
- *
- * This is used when creating a "fixed" ArchiveEntry that doesn't need to
- * participate in the sorting logic.
- */
- DumpId
- createDumpId(void)
- {
- return ++lastDumpId;
- }
-
- /*
- * Return the largest DumpId so far assigned
- */
- DumpId
- getMaxDumpId(void)
- {
- return lastDumpId;
- }
-
- /*
- * Find a DumpableObject by dump ID
- *
- * Returns NULL for invalid ID
- */
- DumpableObject *
- findObjectByDumpId(DumpId dumpId)
- {
- if (dumpId <= 0 || dumpId >= allocedDumpIds)
- return NULL; /* out of range? */
- return dumpIdMap[dumpId];
- }
-
- /*
- * Find a DumpableObject by catalog ID
- *
- * Returns NULL for unknown ID
- *
- * We use binary search in a sorted list that is built on first call.
- * If AssignDumpId() and findObjectByCatalogId() calls were freely intermixed,
- * the code would work, but possibly be very slow. In the current usage
- * pattern that does not happen, indeed we build the list at most twice.
- */
- DumpableObject *
- findObjectByCatalogId(CatalogId catalogId)
- {
- DumpableObject **low;
- DumpableObject **high;
-
- if (!catalogIdMapValid)
- {
- if (catalogIdMap)
- free(catalogIdMap);
- getDumpableObjects(&catalogIdMap, &numCatalogIds);
- if (numCatalogIds > 1)
- qsort((void *) catalogIdMap, numCatalogIds,
- sizeof(DumpableObject *), DOCatalogIdCompare);
- catalogIdMapValid = true;
- }
-
- /*
- * We could use bsearch() here, but the notational cruft of calling
- * bsearch is nearly as bad as doing it ourselves; and the generalized
- * bsearch function is noticeably slower as well.
- */
- if (numCatalogIds <= 0)
- return NULL;
- low = catalogIdMap;
- high = catalogIdMap + (numCatalogIds - 1);
- while (low <= high)
- {
- DumpableObject **middle;
- int difference;
-
- middle = low + (high - low) / 2;
- /* comparison must match DOCatalogIdCompare, below */
- difference = oidcmp((*middle)->catId.oid, catalogId.oid);
- if (difference == 0)
- difference = oidcmp((*middle)->catId.tableoid, catalogId.tableoid);
- if (difference == 0)
- return *middle;
- else if (difference < 0)
- low = middle + 1;
- else
- high = middle - 1;
- }
- return NULL;
- }
-
- /*
- * Find a DumpableObject by OID, in a pre-sorted array of one type of object
- *
- * Returns NULL for unknown OID
- */
- static DumpableObject *
- findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
- {
- DumpableObject **low;
- DumpableObject **high;
-
- /*
- * This is the same as findObjectByCatalogId except we assume we need not
- * look at table OID because the objects are all the same type.
- *
- * We could use bsearch() here, but the notational cruft of calling
- * bsearch is nearly as bad as doing it ourselves; and the generalized
- * bsearch function is noticeably slower as well.
- */
- if (numObjs <= 0)
- return NULL;
- low = indexArray;
- high = indexArray + (numObjs - 1);
- while (low <= high)
- {
- DumpableObject **middle;
- int difference;
-
- middle = low + (high - low) / 2;
- difference = oidcmp((*middle)->catId.oid, oid);
- if (difference == 0)
- return *middle;
- else if (difference < 0)
- low = middle + 1;
- else
- high = middle - 1;
- }
- return NULL;
- }
-
- /*
- * Build an index array of DumpableObject pointers, sorted by OID
- */
- static DumpableObject **
- buildIndexArray(void *objArray, int numObjs, Size objSize)
- {
- DumpableObject **ptrs;
- int i;
-
- ptrs = (DumpableObject **) malloc(numObjs * sizeof(DumpableObject *));
- for (i = 0; i < numObjs; i++)
- ptrs[i] = (DumpableObject *) ((char *) objArray + i * objSize);
-
- /* We can use DOCatalogIdCompare to sort since its first key is OID */
- if (numObjs > 1)
- qsort((void *) ptrs, numObjs, sizeof(DumpableObject *),
- DOCatalogIdCompare);
-
- return ptrs;
- }
-
- /*
- * qsort comparator for pointers to DumpableObjects
- */
- static int
- DOCatalogIdCompare(const void *p1, const void *p2)
- {
- const DumpableObject *obj1 = *(DumpableObject * const *) p1;
- const DumpableObject *obj2 = *(DumpableObject * const *) p2;
- int cmpval;
-
- /*
- * Compare OID first since it's usually unique, whereas there will only be
- * a few distinct values of tableoid.
- */
- cmpval = oidcmp(obj1->catId.oid, obj2->catId.oid);
- if (cmpval == 0)
- cmpval = oidcmp(obj1->catId.tableoid, obj2->catId.tableoid);
- return cmpval;
- }
-
- /*
- * Build an array of pointers to all known dumpable objects
- *
- * This simply creates a modifiable copy of the internal map.
- */
- void
- getDumpableObjects(DumpableObject ***objs, int *numObjs)
- {
- int i,
- j;
-
- *objs = (DumpableObject **)
- pg_malloc(allocedDumpIds * sizeof(DumpableObject *));
- j = 0;
- for (i = 1; i < allocedDumpIds; i++)
- {
- if (dumpIdMap[i])
- (*objs)[j++] = dumpIdMap[i];
- }
- *numObjs = j;
- }
-
- /*
- * Add a dependency link to a DumpableObject
- *
- * Note: duplicate dependencies are currently not eliminated
- */
- void
- addObjectDependency(DumpableObject *dobj, DumpId refId)
- {
- if (dobj->nDeps >= dobj->allocDeps)
- {
- if (dobj->allocDeps <= 0)
- {
- dobj->allocDeps = 16;
- dobj->dependencies = (DumpId *)
- pg_malloc(dobj->allocDeps * sizeof(DumpId));
- }
- else
- {
- dobj->allocDeps *= 2;
- dobj->dependencies = (DumpId *)
- pg_realloc(dobj->dependencies,
- dobj->allocDeps * sizeof(DumpId));
- }
- }
- dobj->dependencies[dobj->nDeps++] = refId;
- }
-
- /*
- * Remove a dependency link from a DumpableObject
- *
- * If there are multiple links, all are removed
- */
- void
- removeObjectDependency(DumpableObject *dobj, DumpId refId)
- {
- int i;
- int j = 0;
-
- for (i = 0; i < dobj->nDeps; i++)
- {
- if (dobj->dependencies[i] != refId)
- dobj->dependencies[j++] = dobj->dependencies[i];
- }
- dobj->nDeps = j;
- }
-
-
- /*
- * findTableByOid
- * finds the entry (in tblinfo) of the table with the given oid
- * returns NULL if not found
- */
- TableInfo *
- findTableByOid(Oid oid)
- {
- return (TableInfo *) findObjectByOid(oid, tblinfoindex, numTables);
- }
-
- /*
- * findTypeByOid
- * finds the entry (in typinfo) of the type with the given oid
- * returns NULL if not found
- */
- TypeInfo *
- findTypeByOid(Oid oid)
- {
- return (TypeInfo *) findObjectByOid(oid, typinfoindex, numTypes);
- }
-
- /*
- * findFuncByOid
- * finds the entry (in funinfo) of the function with the given oid
- * returns NULL if not found
- */
- FuncInfo *
- findFuncByOid(Oid oid)
- {
- return (FuncInfo *) findObjectByOid(oid, funinfoindex, numFuncs);
- }
-
- /*
- * findOprByOid
- * finds the entry (in oprinfo) of the operator with the given oid
- * returns NULL if not found
- */
- OprInfo *
- findOprByOid(Oid oid)
- {
- return (OprInfo *) findObjectByOid(oid, oprinfoindex, numOperators);
- }
-
- /*
- * findCollationByOid
- * finds the entry (in collinfo) of the collation with the given oid
- * returns NULL if not found
- */
- CollInfo *
- findCollationByOid(Oid oid)
- {
- return (CollInfo *) findObjectByOid(oid, collinfoindex, numCollations);
- }
-
-
- /*
- * findParentsByOid
- * find a table's parents in tblinfo[]
- */
- static void
- findParentsByOid(TableInfo *self,
- InhInfo *inhinfo, int numInherits)
- {
- Oid oid = self->dobj.catId.oid;
- int i,
- j;
- int numParents;
-
- numParents = 0;
- for (i = 0; i < numInherits; i++)
- {
- if (inhinfo[i].inhrelid == oid)
- numParents++;
- }
-
- self->numParents = numParents;
-
- if (numParents > 0)
- {
- self->parents = (TableInfo **)
- pg_malloc(sizeof(TableInfo *) * numParents);
- j = 0;
- for (i = 0; i < numInherits; i++)
- {
- if (inhinfo[i].inhrelid == oid)
- {
- TableInfo *parent;
-
- parent = findTableByOid(inhinfo[i].inhparent);
- if (parent == NULL)
- {
- write_msg(NULL, "failed sanity check, parent OID %u of table \"%s\" (OID %u) not found\n",
- inhinfo[i].inhparent,
- self->dobj.name,
- oid);
- exit_nicely();
- }
- self->parents[j++] = parent;
- }
- }
- }
- else
- self->parents = NULL;
- }
-
- /*
- * parseOidArray
- * parse a string of numbers delimited by spaces into a character array
- *
- * Note: actually this is used for both Oids and potentially-signed
- * attribute numbers. This should cause no trouble, but we could split
- * the function into two functions with different argument types if it does.
- */
-
- void
- parseOidArray(const char *str, Oid *array, int arraysize)
- {
- int j,
- argNum;
- char temp[100];
- char s;
-
- argNum = 0;
- j = 0;
- for (;;)
- {
- s = *str++;
- if (s == ' ' || s == '\0')
- {
- if (j > 0)
- {
- if (argNum >= arraysize)
- {
- write_msg(NULL, "could not parse numeric array \"%s\": too many numbers\n", str);
- exit_nicely();
- }
- temp[j] = '\0';
- array[argNum++] = atooid(temp);
- j = 0;
- }
- if (s == '\0')
- break;
- }
- else
- {
- if (!(isdigit((unsigned char) s) || s == '-') ||
- j >= sizeof(temp) - 1)
- {
- write_msg(NULL, "could not parse numeric array \"%s\": invalid character in number\n", str);
- exit_nicely();
- }
- temp[j++] = s;
- }
- }
-
- while (argNum < arraysize)
- array[argNum++] = InvalidOid;
- }
-
-
- /*
- * strInArray:
- * takes in a string and a string array and the number of elements in the
- * string array.
- * returns the index if the string is somewhere in the array, -1 otherwise
- */
-
- static int
- strInArray(const char *pattern, char **arr, int arr_size)
- {
- int i;
-
- for (i = 0; i < arr_size; i++)
- {
- if (strcmp(pattern, arr[i]) == 0)
- return i;
- }
- return -1;
- }
-
-
- /*
- * Support for simple list operations
- */
-
- void
- simple_oid_list_append(SimpleOidList *list, Oid val)
- {
- SimpleOidListCell *cell;
-
- cell = (SimpleOidListCell *) pg_malloc(sizeof(SimpleOidListCell));
- cell->next = NULL;
- cell->val = val;
-
- if (list->tail)
- list->tail->next = cell;
- else
- list->head = cell;
- list->tail = cell;
- }
-
- void
- simple_string_list_append(SimpleStringList *list, const char *val)
- {
- SimpleStringListCell *cell;
-
- /* this calculation correctly accounts for the null trailing byte */
- cell = (SimpleStringListCell *)
- pg_malloc(sizeof(SimpleStringListCell) + strlen(val));
- cell->next = NULL;
- strcpy(cell->val, val);
-
- if (list->tail)
- list->tail->next = cell;
- else
- list->head = cell;
- list->tail = cell;
- }
-
- bool
- simple_oid_list_member(SimpleOidList *list, Oid val)
- {
- SimpleOidListCell *cell;
-
- for (cell = list->head; cell; cell = cell->next)
- {
- if (cell->val == val)
- return true;
- }
- return false;
- }
-
- bool
- simple_string_list_member(SimpleStringList *list, const char *val)
- {
- SimpleStringListCell *cell;
-
- for (cell = list->head; cell; cell = cell->next)
- {
- if (strcmp(cell->val, val) == 0)
- return true;
- }
- return false;
- }
-
-
/*
* Safer versions of some standard C library functions. If an
* out-of-memory condition occurs, these functions will bail out
* safely; therefore, their return value is guaranteed to be non-NULL.
! *
! * XXX need to refactor things so that these can be in a file that can be
! * shared by pg_dumpall and pg_restore as well as pg_dump.
*/
char *
--- 14,29 ----
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
+ #include "pg_backup.h"
+ #include "common.h"
#include <ctype.h>
/*
* Safer versions of some standard C library functions. If an
* out-of-memory condition occurs, these functions will bail out
* safely; therefore, their return value is guaranteed to be non-NULL.
! * We also report the program name and close the database connection.
*/
char *
*************** pg_calloc(size_t nmemb, size_t size)
*** 1020,1026 ****
tmp = calloc(nmemb, size);
if (!tmp)
! exit_horribly(NULL, NULL, "out of memory\n");
return tmp;
}
--- 57,63 ----
tmp = calloc(nmemb, size);
if (!tmp)
! exit_horribly(NULL, NULL, _("out of memory\n"));
return tmp;
}
*************** pg_realloc(void *ptr, size_t size)
*** 1031,1036 ****
tmp = realloc(ptr, size);
if (!tmp)
! exit_horribly(NULL, NULL, "out of memory\n");
return tmp;
}
--- 68,73 ----
tmp = realloc(ptr, size);
if (!tmp)
! exit_horribly(NULL, NULL, _("out of memory\n"));
return tmp;
}
diff --git a/src/bin/pg_dump/common.h b/src/bin/pg_dump/common.h
new file mode 100644
index ...742d9f6
*** a/src/bin/pg_dump/common.h
--- b/src/bin/pg_dump/common.h
***************
*** 0 ****
--- 1,24 ----
+ /*-------------------------------------------------------------------------
+ *
+ * common.h
+ * Common header file for the pg_dump, pg_dumpall, and pg_restore
+ *
+ * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/bin/pg_dump/common.h
+ *
+ *-------------------------------------------------------------------------
+ */
+
+ #ifndef COMMON_H
+ #define COMMON_H
+
+ #include "postgres_fe.h"
+
+ extern char *pg_strdup(const char *string);
+ extern void *pg_malloc(size_t size);
+ extern void *pg_calloc(size_t nmemb, size_t size);
+ extern void *pg_realloc(void *ptr, size_t size);
+
+ #endif /* COMMON_H */
diff --git a/src/bin/pg_dump/compress_io.c b/src/bin/pg_dump/compress_io.c
new file mode 100644
index 8540a75..8375762
*** a/src/bin/pg_dump/compress_io.c
--- b/src/bin/pg_dump/compress_io.c
***************
*** 53,58 ****
--- 53,59 ----
*/
#include "compress_io.h"
+ #include "common.h"
/*----------------------
* Compressor API
*************** AllocateCompressor(int compression, Writ
*** 135,143 ****
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->writeF = writeF;
cs->comprAlg = alg;
--- 136,142 ----
die_horribly(NULL, modulename, "not built with zlib support\n");
#endif
! cs = (CompressorState *) pg_calloc(1, sizeof(CompressorState));
cs->writeF = writeF;
cs->comprAlg = alg;
*************** InitCompressorZlib(CompressorState *cs,
*** 221,229 ****
{
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->zalloc = Z_NULL;
zp->zfree = Z_NULL;
zp->opaque = Z_NULL;
--- 220,226 ----
{
z_streamp zp;
! zp = cs->zp = (z_streamp) pg_malloc(sizeof(z_stream));
zp->zalloc = Z_NULL;
zp->zfree = Z_NULL;
zp->opaque = Z_NULL;
*************** InitCompressorZlib(CompressorState *cs,
*** 233,244 ****
* 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->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",
--- 230,238 ----
* actually allocate one extra byte because some routines want to append a
* trailing zero byte to the zlib output.
*/
! cs->zlibOut = (char *) pg_malloc(ZLIB_OUT_SIZE + 1);
cs->zlibOutSize = ZLIB_OUT_SIZE;
if (deflateInit(zp, level) != Z_OK)
die_horribly(NULL, modulename,
"could not initialize compression library: %s\n",
*************** ReadDataFromArchiveZlib(ArchiveHandle *A
*** 338,358 ****
char *buf;
size_t buflen;
! zp = (z_streamp) malloc(sizeof(z_stream));
! if (zp == NULL)
! die_horribly(NULL, modulename, "out of memory\n");
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");
buflen = ZLIB_IN_SIZE;
! out = malloc(ZLIB_OUT_SIZE + 1);
! if (out == NULL)
! die_horribly(NULL, modulename, "out of memory\n");
if (inflateInit(zp) != Z_OK)
die_horribly(NULL, modulename,
--- 332,346 ----
char *buf;
size_t buflen;
! zp = (z_streamp) pg_malloc(sizeof(z_stream));
zp->zalloc = Z_NULL;
zp->zfree = Z_NULL;
zp->opaque = Z_NULL;
! buf = pg_malloc(ZLIB_IN_SIZE);
buflen = ZLIB_IN_SIZE;
! out = pg_malloc(ZLIB_OUT_SIZE + 1);
if (inflateInit(zp) != Z_OK)
die_horribly(NULL, modulename,
*************** ReadDataFromArchiveNone(ArchiveHandle *A
*** 417,425 ****
char *buf;
size_t buflen;
! buf = malloc(ZLIB_OUT_SIZE);
! if (buf == NULL)
! die_horribly(NULL, modulename, "out of memory\n");
buflen = ZLIB_OUT_SIZE;
while ((cnt = readF(AH, &buf, &buflen)))
--- 405,411 ----
char *buf;
size_t buflen;
! buf = pg_malloc(ZLIB_OUT_SIZE);
buflen = ZLIB_OUT_SIZE;
while ((cnt = readF(AH, &buf, &buflen)))
*************** cfopen_read(const char *path, const char
*** 491,500 ****
if (fp == NULL)
{
int fnamelen = strlen(path) + 4;
! char *fname = malloc(fnamelen);
!
! if (fname == NULL)
! die_horribly(NULL, modulename, "Out of memory\n");
snprintf(fname, fnamelen, "%s%s", path, ".gz");
fp = cfopen(fname, mode, 1);
--- 477,483 ----
if (fp == NULL)
{
int fnamelen = strlen(path) + 4;
! char *fname = pg_malloc(fnamelen);
snprintf(fname, fnamelen, "%s%s", path, ".gz");
fp = cfopen(fname, mode, 1);
*************** cfopen_write(const char *path, const cha
*** 525,534 ****
{
#ifdef HAVE_LIBZ
int fnamelen = strlen(path) + 4;
! char *fname = malloc(fnamelen);
!
! if (fname == NULL)
! die_horribly(NULL, modulename, "Out of memory\n");
snprintf(fname, fnamelen, "%s%s", path, ".gz");
fp = cfopen(fname, mode, 1);
--- 508,514 ----
{
#ifdef HAVE_LIBZ
int fnamelen = strlen(path) + 4;
! char *fname = pg_malloc(fnamelen);
snprintf(fname, fnamelen, "%s%s", path, ".gz");
fp = cfopen(fname, mode, 1);
*************** cfopen_write(const char *path, const cha
*** 548,557 ****
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");
if (compression != 0)
{
--- 528,534 ----
cfp *
cfopen(const char *path, const char *mode, int compression)
{
! cfp *fp = pg_malloc(sizeof(cfp));
if (compression != 0)
{
diff --git a/src/bin/pg_dump/dumpcatalog.c b/src/bin/pg_dump/dumpcatalog.c
new file mode 100644
index ...9747d47
*** a/src/bin/pg_dump/dumpcatalog.c
--- b/src/bin/pg_dump/dumpcatalog.c
***************
*** 0 ****
--- 1,978 ----
+ /*-------------------------------------------------------------------------
+ *
+ * common.c
+ * catalog routines used by pg_dump
+ *
+ * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ *
+ * IDENTIFICATION
+ * src/bin/pg_dump/dumpcatalog.c
+ *
+ *-------------------------------------------------------------------------
+ */
+ #include "postgres_fe.h"
+
+ #include <ctype.h>
+
+ #include "catalog/pg_class.h"
+
+ #include "pg_backup_archiver.h"
+ #include "common.h"
+
+
+ /*
+ * Variables for mapping DumpId to DumpableObject
+ */
+ static DumpableObject **dumpIdMap = NULL;
+ static int allocedDumpIds = 0;
+ static DumpId lastDumpId = 0;
+
+ /*
+ * Variables for mapping CatalogId to DumpableObject
+ */
+ static bool catalogIdMapValid = false;
+ static DumpableObject **catalogIdMap = NULL;
+ static int numCatalogIds = 0;
+
+ /*
+ * These variables are static to avoid the notational cruft of having to pass
+ * them into findTableByOid() and friends. For each of these arrays, we
+ * build a sorted-by-OID index array immediately after it's built, and then
+ * we use binary search in findTableByOid() and friends. (qsort'ing the base
+ * arrays themselves would be simpler, but it doesn't work because pg_dump.c
+ * may have already established pointers between items.)
+ */
+ static TableInfo *tblinfo;
+ static TypeInfo *typinfo;
+ static FuncInfo *funinfo;
+ static OprInfo *oprinfo;
+ static int numTables;
+ static int numTypes;
+ static int numFuncs;
+ static int numOperators;
+ static int numCollations;
+ static DumpableObject **tblinfoindex;
+ static DumpableObject **typinfoindex;
+ static DumpableObject **funinfoindex;
+ static DumpableObject **oprinfoindex;
+ static DumpableObject **collinfoindex;
+
+
+ static void flagInhTables(TableInfo *tbinfo, int numTables,
+ InhInfo *inhinfo, int numInherits);
+ static void flagInhAttrs(TableInfo *tblinfo, int numTables);
+ static DumpableObject **buildIndexArray(void *objArray, int numObjs,
+ Size objSize);
+ static int DOCatalogIdCompare(const void *p1, const void *p2);
+ static void findParentsByOid(TableInfo *self,
+ InhInfo *inhinfo, int numInherits);
+ static int strInArray(const char *pattern, char **arr, int arr_size);
+
+
+ /*
+ * getSchemaData
+ * Collect information about all potentially dumpable objects
+ */
+ TableInfo *
+ getSchemaData(int *numTablesPtr)
+ {
+ ExtensionInfo *extinfo;
+ InhInfo *inhinfo;
+ CollInfo *collinfo;
+ int numNamespaces;
+ int numExtensions;
+ int numAggregates;
+ int numInherits;
+ int numRules;
+ int numProcLangs;
+ int numCasts;
+ int numOpclasses;
+ int numOpfamilies;
+ int numConversions;
+ int numTSParsers;
+ int numTSTemplates;
+ int numTSDicts;
+ int numTSConfigs;
+ int numForeignDataWrappers;
+ int numForeignServers;
+ int numDefaultACLs;
+
+ if (g_verbose)
+ write_msg(NULL, "reading schemas\n");
+ getNamespaces(&numNamespaces);
+
+ /*
+ * getTables should be done as soon as possible, so as to minimize the
+ * window between starting our transaction and acquiring per-table locks.
+ * However, we have to do getNamespaces first because the tables get
+ * linked to their containing namespaces during getTables.
+ */
+ if (g_verbose)
+ write_msg(NULL, "reading user-defined tables\n");
+ tblinfo = getTables(&numTables);
+ tblinfoindex = buildIndexArray(tblinfo, numTables, sizeof(TableInfo));
+
+ if (g_verbose)
+ write_msg(NULL, "reading extensions\n");
+ extinfo = getExtensions(&numExtensions);
+
+ if (g_verbose)
+ write_msg(NULL, "reading user-defined functions\n");
+ funinfo = getFuncs(&numFuncs);
+ funinfoindex = buildIndexArray(funinfo, numFuncs, sizeof(FuncInfo));
+
+ /* this must be after getTables and getFuncs */
+ if (g_verbose)
+ write_msg(NULL, "reading user-defined types\n");
+ typinfo = getTypes(&numTypes);
+ typinfoindex = buildIndexArray(typinfo, numTypes, sizeof(TypeInfo));
+
+ /* this must be after getFuncs, too */
+ if (g_verbose)
+ write_msg(NULL, "reading procedural languages\n");
+ getProcLangs(&numProcLangs);
+
+ if (g_verbose)
+ write_msg(NULL, "reading user-defined aggregate functions\n");
+ getAggregates(&numAggregates);
+
+ if (g_verbose)
+ write_msg(NULL, "reading user-defined operators\n");
+ oprinfo = getOperators(&numOperators);
+ oprinfoindex = buildIndexArray(oprinfo, numOperators, sizeof(OprInfo));
+
+ if (g_verbose)
+ write_msg(NULL, "reading user-defined operator classes\n");
+ getOpclasses(&numOpclasses);
+
+ if (g_verbose)
+ write_msg(NULL, "reading user-defined operator families\n");
+ getOpfamilies(&numOpfamilies);
+
+ if (g_verbose)
+ write_msg(NULL, "reading user-defined text search parsers\n");
+ getTSParsers(&numTSParsers);
+
+ if (g_verbose)
+ write_msg(NULL, "reading user-defined text search templates\n");
+ getTSTemplates(&numTSTemplates);
+
+ if (g_verbose)
+ write_msg(NULL, "reading user-defined text search dictionaries\n");
+ getTSDictionaries(&numTSDicts);
+
+ if (g_verbose)
+ write_msg(NULL, "reading user-defined text search configurations\n");
+ getTSConfigurations(&numTSConfigs);
+
+ if (g_verbose)
+ write_msg(NULL, "reading user-defined foreign-data wrappers\n");
+ getForeignDataWrappers(&numForeignDataWrappers);
+
+ if (g_verbose)
+ write_msg(NULL, "reading user-defined foreign servers\n");
+ getForeignServers(&numForeignServers);
+
+ if (g_verbose)
+ write_msg(NULL, "reading default privileges\n");
+ getDefaultACLs(&numDefaultACLs);
+
+ if (g_verbose)
+ write_msg(NULL, "reading user-defined collations\n");
+ collinfo = getCollations(&numCollations);
+ collinfoindex = buildIndexArray(collinfo, numCollations, sizeof(CollInfo));
+
+ if (g_verbose)
+ write_msg(NULL, "reading user-defined conversions\n");
+ getConversions(&numConversions);
+
+ if (g_verbose)
+ write_msg(NULL, "reading type casts\n");
+ getCasts(&numCasts);
+
+ if (g_verbose)
+ write_msg(NULL, "reading table inheritance information\n");
+ inhinfo = getInherits(&numInherits);
+
+ if (g_verbose)
+ write_msg(NULL, "reading rewrite rules\n");
+ getRules(&numRules);
+
+ /*
+ * Identify extension member objects and mark them as not to be dumped.
+ * This must happen after reading all objects that can be direct members
+ * of extensions, but before we begin to process table subsidiary objects.
+ */
+ if (g_verbose)
+ write_msg(NULL, "finding extension members\n");
+ getExtensionMembership(extinfo, numExtensions);
+
+ /* Link tables to parents, mark parents of target tables interesting */
+ if (g_verbose)
+ write_msg(NULL, "finding inheritance relationships\n");
+ flagInhTables(tblinfo, numTables, inhinfo, numInherits);
+
+ if (g_verbose)
+ write_msg(NULL, "reading column info for interesting tables\n");
+ getTableAttrs(tblinfo, numTables);
+
+ if (g_verbose)
+ write_msg(NULL, "flagging inherited columns in subtables\n");
+ flagInhAttrs(tblinfo, numTables);
+
+ if (g_verbose)
+ write_msg(NULL, "reading indexes\n");
+ getIndexes(tblinfo, numTables);
+
+ if (g_verbose)
+ write_msg(NULL, "reading constraints\n");
+ getConstraints(tblinfo, numTables);
+
+ if (g_verbose)
+ write_msg(NULL, "reading triggers\n");
+ getTriggers(tblinfo, numTables);
+
+ *numTablesPtr = numTables;
+ return tblinfo;
+ }
+
+ /* flagInhTables -
+ * Fill in parent link fields of every target table, and mark
+ * parents of target tables as interesting
+ *
+ * Note that only direct ancestors of targets are marked interesting.
+ * This is sufficient; we don't much care whether they inherited their
+ * attributes or not.
+ *
+ * modifies tblinfo
+ */
+ static void
+ flagInhTables(TableInfo *tblinfo, int numTables,
+ InhInfo *inhinfo, int numInherits)
+ {
+ int i,
+ j;
+ int numParents;
+ TableInfo **parents;
+
+ for (i = 0; i < numTables; i++)
+ {
+ /* Sequences and views never have parents */
+ if (tblinfo[i].relkind == RELKIND_SEQUENCE ||
+ tblinfo[i].relkind == RELKIND_VIEW)
+ continue;
+
+ /* Don't bother computing anything for non-target tables, either */
+ if (!tblinfo[i].dobj.dump)
+ continue;
+
+ /* Find all the immediate parent tables */
+ findParentsByOid(&tblinfo[i], inhinfo, numInherits);
+
+ /* Mark the parents as interesting for getTableAttrs */
+ numParents = tblinfo[i].numParents;
+ parents = tblinfo[i].parents;
+ for (j = 0; j < numParents; j++)
+ parents[j]->interesting = true;
+ }
+ }
+
+ /* flagInhAttrs -
+ * for each dumpable table in tblinfo, flag its inherited attributes
+ * so when we dump the table out, we don't dump out the inherited attributes
+ *
+ * modifies tblinfo
+ */
+ static void
+ flagInhAttrs(TableInfo *tblinfo, int numTables)
+ {
+ int i,
+ j,
+ k;
+
+ for (i = 0; i < numTables; i++)
+ {
+ TableInfo *tbinfo = &(tblinfo[i]);
+ int numParents;
+ TableInfo **parents;
+ TableInfo *parent;
+
+ /* Sequences and views never have parents */
+ if (tbinfo->relkind == RELKIND_SEQUENCE ||
+ tbinfo->relkind == RELKIND_VIEW)
+ continue;
+
+ /* Don't bother computing anything for non-target tables, either */
+ if (!tbinfo->dobj.dump)
+ continue;
+
+ numParents = tbinfo->numParents;
+ parents = tbinfo->parents;
+
+ if (numParents == 0)
+ continue; /* nothing to see here, move along */
+
+ /*----------------------------------------------------------------
+ * For each attr, check the parent info: if no parent has an attr
+ * with the same name, then it's not inherited. If there *is* an
+ * attr with the same name, then only dump it if:
+ *
+ * - it is NOT NULL and zero parents are NOT NULL
+ * OR
+ * - it has a default value AND the default value does not match
+ * all parent default values, or no parents specify a default.
+ *
+ * See discussion on -hackers around 2-Apr-2001.
+ *----------------------------------------------------------------
+ */
+ for (j = 0; j < tbinfo->numatts; j++)
+ {
+ bool foundAttr; /* Attr was found in a parent */
+ bool foundNotNull; /* Attr was NOT NULL in a parent */
+ bool defaultsMatch; /* All non-empty defaults match */
+ bool defaultsFound; /* Found a default in a parent */
+ AttrDefInfo *attrDef;
+
+ foundAttr = false;
+ foundNotNull = false;
+ defaultsMatch = true;
+ defaultsFound = false;
+
+ attrDef = tbinfo->attrdefs[j];
+
+ for (k = 0; k < numParents; k++)
+ {
+ int inhAttrInd;
+
+ parent = parents[k];
+ inhAttrInd = strInArray(tbinfo->attnames[j],
+ parent->attnames,
+ parent->numatts);
+
+ if (inhAttrInd != -1)
+ {
+ AttrDefInfo *inhDef = parent->attrdefs[inhAttrInd];
+
+ foundAttr = true;
+ foundNotNull |= parent->notnull[inhAttrInd];
+ if (inhDef != NULL)
+ {
+ defaultsFound = true;
+
+ /*
+ * If any parent has a default and the child doesn't,
+ * we have to emit an explicit DEFAULT NULL clause for
+ * the child, else the parent's default will win.
+ */
+ if (attrDef == NULL)
+ {
+ attrDef = (AttrDefInfo *) pg_malloc(sizeof(AttrDefInfo));
+ attrDef->dobj.objType = DO_ATTRDEF;
+ attrDef->dobj.catId.tableoid = 0;
+ attrDef->dobj.catId.oid = 0;
+ AssignDumpId(&attrDef->dobj);
+ attrDef->adtable = tbinfo;
+ attrDef->adnum = j + 1;
+ attrDef->adef_expr = pg_strdup("NULL");
+
+ attrDef->dobj.name = pg_strdup(tbinfo->dobj.name);
+ attrDef->dobj.namespace = tbinfo->dobj.namespace;
+
+ attrDef->dobj.dump = tbinfo->dobj.dump;
+
+ attrDef->separate = false;
+ addObjectDependency(&tbinfo->dobj,
+ attrDef->dobj.dumpId);
+
+ tbinfo->attrdefs[j] = attrDef;
+ }
+ if (strcmp(attrDef->adef_expr, inhDef->adef_expr) != 0)
+ {
+ defaultsMatch = false;
+
+ /*
+ * Whenever there is a non-matching parent
+ * default, add a dependency to force the parent
+ * default to be dumped first, in case the
+ * defaults end up being dumped as separate
+ * commands. Otherwise the parent default will
+ * override the child's when it is applied.
+ */
+ addObjectDependency(&attrDef->dobj,
+ inhDef->dobj.dumpId);
+ }
+ }
+ }
+ }
+
+ /*
+ * Based on the scan of the parents, decide if we can rely on the
+ * inherited attr
+ */
+ if (foundAttr) /* Attr was inherited */
+ {
+ /* Set inherited flag by default */
+ tbinfo->inhAttrs[j] = true;
+ tbinfo->inhAttrDef[j] = true;
+ tbinfo->inhNotNull[j] = true;
+
+ /*
+ * Clear it if attr had a default, but parents did not, or
+ * mismatch
+ */
+ if ((attrDef != NULL) && (!defaultsFound || !defaultsMatch))
+ {
+ tbinfo->inhAttrs[j] = false;
+ tbinfo->inhAttrDef[j] = false;
+ }
+
+ /*
+ * Clear it if NOT NULL and none of the parents were NOT NULL
+ */
+ if (tbinfo->notnull[j] && !foundNotNull)
+ {
+ tbinfo->inhAttrs[j] = false;
+ tbinfo->inhNotNull[j] = false;
+ }
+
+ /* Clear it if attr has local definition */
+ if (tbinfo->attislocal[j])
+ tbinfo->inhAttrs[j] = false;
+ }
+ }
+ }
+ }
+
+ /*
+ * AssignDumpId
+ * Given a newly-created dumpable object, assign a dump ID,
+ * and enter the object into the lookup table.
+ *
+ * The caller is expected to have filled in objType and catId,
+ * but not any of the other standard fields of a DumpableObject.
+ */
+ void
+ AssignDumpId(DumpableObject *dobj)
+ {
+ dobj->dumpId = ++lastDumpId;
+ dobj->name = NULL; /* must be set later */
+ dobj->namespace = NULL; /* may be set later */
+ dobj->dump = true; /* default assumption */
+ dobj->ext_member = false; /* default assumption */
+ dobj->dependencies = NULL;
+ dobj->nDeps = 0;
+ dobj->allocDeps = 0;
+
+ while (dobj->dumpId >= allocedDumpIds)
+ {
+ int newAlloc;
+
+ if (allocedDumpIds <= 0)
+ {
+ newAlloc = 256;
+ dumpIdMap = (DumpableObject **)
+ pg_malloc(newAlloc * sizeof(DumpableObject *));
+ }
+ else
+ {
+ newAlloc = allocedDumpIds * 2;
+ dumpIdMap = (DumpableObject **)
+ pg_realloc(dumpIdMap, newAlloc * sizeof(DumpableObject *));
+ }
+ memset(dumpIdMap + allocedDumpIds, 0,
+ (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
+ allocedDumpIds = newAlloc;
+ }
+ dumpIdMap[dobj->dumpId] = dobj;
+
+ /* mark catalogIdMap invalid, but don't rebuild it yet */
+ catalogIdMapValid = false;
+ }
+
+ /*
+ * Assign a DumpId that's not tied to a DumpableObject.
+ *
+ * This is used when creating a "fixed" ArchiveEntry that doesn't need to
+ * participate in the sorting logic.
+ */
+ DumpId
+ createDumpId(void)
+ {
+ return ++lastDumpId;
+ }
+
+ /*
+ * Return the largest DumpId so far assigned
+ */
+ DumpId
+ getMaxDumpId(void)
+ {
+ return lastDumpId;
+ }
+
+ /*
+ * Find a DumpableObject by dump ID
+ *
+ * Returns NULL for invalid ID
+ */
+ DumpableObject *
+ findObjectByDumpId(DumpId dumpId)
+ {
+ if (dumpId <= 0 || dumpId >= allocedDumpIds)
+ return NULL; /* out of range? */
+ return dumpIdMap[dumpId];
+ }
+
+ /*
+ * Find a DumpableObject by catalog ID
+ *
+ * Returns NULL for unknown ID
+ *
+ * We use binary search in a sorted list that is built on first call.
+ * If AssignDumpId() and findObjectByCatalogId() calls were freely intermixed,
+ * the code would work, but possibly be very slow. In the current usage
+ * pattern that does not happen, indeed we build the list at most twice.
+ */
+ DumpableObject *
+ findObjectByCatalogId(CatalogId catalogId)
+ {
+ DumpableObject **low;
+ DumpableObject **high;
+
+ if (!catalogIdMapValid)
+ {
+ if (catalogIdMap)
+ free(catalogIdMap);
+ getDumpableObjects(&catalogIdMap, &numCatalogIds);
+ if (numCatalogIds > 1)
+ qsort((void *) catalogIdMap, numCatalogIds,
+ sizeof(DumpableObject *), DOCatalogIdCompare);
+ catalogIdMapValid = true;
+ }
+
+ /*
+ * We could use bsearch() here, but the notational cruft of calling
+ * bsearch is nearly as bad as doing it ourselves; and the generalized
+ * bsearch function is noticeably slower as well.
+ */
+ if (numCatalogIds <= 0)
+ return NULL;
+ low = catalogIdMap;
+ high = catalogIdMap + (numCatalogIds - 1);
+ while (low <= high)
+ {
+ DumpableObject **middle;
+ int difference;
+
+ middle = low + (high - low) / 2;
+ /* comparison must match DOCatalogIdCompare, below */
+ difference = oidcmp((*middle)->catId.oid, catalogId.oid);
+ if (difference == 0)
+ difference = oidcmp((*middle)->catId.tableoid, catalogId.tableoid);
+ if (difference == 0)
+ return *middle;
+ else if (difference < 0)
+ low = middle + 1;
+ else
+ high = middle - 1;
+ }
+ return NULL;
+ }
+
+ /*
+ * Find a DumpableObject by OID, in a pre-sorted array of one type of object
+ *
+ * Returns NULL for unknown OID
+ */
+ static DumpableObject *
+ findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
+ {
+ DumpableObject **low;
+ DumpableObject **high;
+
+ /*
+ * This is the same as findObjectByCatalogId except we assume we need not
+ * look at table OID because the objects are all the same type.
+ *
+ * We could use bsearch() here, but the notational cruft of calling
+ * bsearch is nearly as bad as doing it ourselves; and the generalized
+ * bsearch function is noticeably slower as well.
+ */
+ if (numObjs <= 0)
+ return NULL;
+ low = indexArray;
+ high = indexArray + (numObjs - 1);
+ while (low <= high)
+ {
+ DumpableObject **middle;
+ int difference;
+
+ middle = low + (high - low) / 2;
+ difference = oidcmp((*middle)->catId.oid, oid);
+ if (difference == 0)
+ return *middle;
+ else if (difference < 0)
+ low = middle + 1;
+ else
+ high = middle - 1;
+ }
+ return NULL;
+ }
+
+ /*
+ * Build an index array of DumpableObject pointers, sorted by OID
+ */
+ static DumpableObject **
+ buildIndexArray(void *objArray, int numObjs, Size objSize)
+ {
+ DumpableObject **ptrs;
+ int i;
+
+ ptrs = (DumpableObject **) pg_malloc(numObjs * sizeof(DumpableObject *));
+ for (i = 0; i < numObjs; i++)
+ ptrs[i] = (DumpableObject *) ((char *) objArray + i * objSize);
+
+ /* We can use DOCatalogIdCompare to sort since its first key is OID */
+ if (numObjs > 1)
+ qsort((void *) ptrs, numObjs, sizeof(DumpableObject *),
+ DOCatalogIdCompare);
+
+ return ptrs;
+ }
+
+ /*
+ * qsort comparator for pointers to DumpableObjects
+ */
+ static int
+ DOCatalogIdCompare(const void *p1, const void *p2)
+ {
+ const DumpableObject *obj1 = *(DumpableObject * const *) p1;
+ const DumpableObject *obj2 = *(DumpableObject * const *) p2;
+ int cmpval;
+
+ /*
+ * Compare OID first since it's usually unique, whereas there will only be
+ * a few distinct values of tableoid.
+ */
+ cmpval = oidcmp(obj1->catId.oid, obj2->catId.oid);
+ if (cmpval == 0)
+ cmpval = oidcmp(obj1->catId.tableoid, obj2->catId.tableoid);
+ return cmpval;
+ }
+
+ /*
+ * Build an array of pointers to all known dumpable objects
+ *
+ * This simply creates a modifiable copy of the internal map.
+ */
+ void
+ getDumpableObjects(DumpableObject ***objs, int *numObjs)
+ {
+ int i,
+ j;
+
+ *objs = (DumpableObject **)
+ pg_malloc(allocedDumpIds * sizeof(DumpableObject *));
+ j = 0;
+ for (i = 1; i < allocedDumpIds; i++)
+ {
+ if (dumpIdMap[i])
+ (*objs)[j++] = dumpIdMap[i];
+ }
+ *numObjs = j;
+ }
+
+ /*
+ * Add a dependency link to a DumpableObject
+ *
+ * Note: duplicate dependencies are currently not eliminated
+ */
+ void
+ addObjectDependency(DumpableObject *dobj, DumpId refId)
+ {
+ if (dobj->nDeps >= dobj->allocDeps)
+ {
+ if (dobj->allocDeps <= 0)
+ {
+ dobj->allocDeps = 16;
+ dobj->dependencies = (DumpId *)
+ pg_malloc(dobj->allocDeps * sizeof(DumpId));
+ }
+ else
+ {
+ dobj->allocDeps *= 2;
+ dobj->dependencies = (DumpId *)
+ pg_realloc(dobj->dependencies,
+ dobj->allocDeps * sizeof(DumpId));
+ }
+ }
+ dobj->dependencies[dobj->nDeps++] = refId;
+ }
+
+ /*
+ * Remove a dependency link from a DumpableObject
+ *
+ * If there are multiple links, all are removed
+ */
+ void
+ removeObjectDependency(DumpableObject *dobj, DumpId refId)
+ {
+ int i;
+ int j = 0;
+
+ for (i = 0; i < dobj->nDeps; i++)
+ {
+ if (dobj->dependencies[i] != refId)
+ dobj->dependencies[j++] = dobj->dependencies[i];
+ }
+ dobj->nDeps = j;
+ }
+
+
+ /*
+ * findTableByOid
+ * finds the entry (in tblinfo) of the table with the given oid
+ * returns NULL if not found
+ */
+ TableInfo *
+ findTableByOid(Oid oid)
+ {
+ return (TableInfo *) findObjectByOid(oid, tblinfoindex, numTables);
+ }
+
+ /*
+ * findTypeByOid
+ * finds the entry (in typinfo) of the type with the given oid
+ * returns NULL if not found
+ */
+ TypeInfo *
+ findTypeByOid(Oid oid)
+ {
+ return (TypeInfo *) findObjectByOid(oid, typinfoindex, numTypes);
+ }
+
+ /*
+ * findFuncByOid
+ * finds the entry (in funinfo) of the function with the given oid
+ * returns NULL if not found
+ */
+ FuncInfo *
+ findFuncByOid(Oid oid)
+ {
+ return (FuncInfo *) findObjectByOid(oid, funinfoindex, numFuncs);
+ }
+
+ /*
+ * findOprByOid
+ * finds the entry (in oprinfo) of the operator with the given oid
+ * returns NULL if not found
+ */
+ OprInfo *
+ findOprByOid(Oid oid)
+ {
+ return (OprInfo *) findObjectByOid(oid, oprinfoindex, numOperators);
+ }
+
+ /*
+ * findCollationByOid
+ * finds the entry (in collinfo) of the collation with the given oid
+ * returns NULL if not found
+ */
+ CollInfo *
+ findCollationByOid(Oid oid)
+ {
+ return (CollInfo *) findObjectByOid(oid, collinfoindex, numCollations);
+ }
+
+
+ /*
+ * findParentsByOid
+ * find a table's parents in tblinfo[]
+ */
+ static void
+ findParentsByOid(TableInfo *self,
+ InhInfo *inhinfo, int numInherits)
+ {
+ Oid oid = self->dobj.catId.oid;
+ int i,
+ j;
+ int numParents;
+
+ numParents = 0;
+ for (i = 0; i < numInherits; i++)
+ {
+ if (inhinfo[i].inhrelid == oid)
+ numParents++;
+ }
+
+ self->numParents = numParents;
+
+ if (numParents > 0)
+ {
+ self->parents = (TableInfo **)
+ pg_malloc(sizeof(TableInfo *) * numParents);
+ j = 0;
+ for (i = 0; i < numInherits; i++)
+ {
+ if (inhinfo[i].inhrelid == oid)
+ {
+ TableInfo *parent;
+
+ parent = findTableByOid(inhinfo[i].inhparent);
+ if (parent == NULL)
+ {
+ write_msg(NULL, "failed sanity check, parent OID %u of table \"%s\" (OID %u) not found\n",
+ inhinfo[i].inhparent,
+ self->dobj.name,
+ oid);
+ exit_nicely();
+ }
+ self->parents[j++] = parent;
+ }
+ }
+ }
+ else
+ self->parents = NULL;
+ }
+
+ /*
+ * parseOidArray
+ * parse a string of numbers delimited by spaces into a character array
+ *
+ * Note: actually this is used for both Oids and potentially-signed
+ * attribute numbers. This should cause no trouble, but we could split
+ * the function into two functions with different argument types if it does.
+ */
+
+ void
+ parseOidArray(const char *str, Oid *array, int arraysize)
+ {
+ int j,
+ argNum;
+ char temp[100];
+ char s;
+
+ argNum = 0;
+ j = 0;
+ for (;;)
+ {
+ s = *str++;
+ if (s == ' ' || s == '\0')
+ {
+ if (j > 0)
+ {
+ if (argNum >= arraysize)
+ {
+ write_msg(NULL, "could not parse numeric array \"%s\": too many numbers\n", str);
+ exit_nicely();
+ }
+ temp[j] = '\0';
+ array[argNum++] = atooid(temp);
+ j = 0;
+ }
+ if (s == '\0')
+ break;
+ }
+ else
+ {
+ if (!(isdigit((unsigned char) s) || s == '-') ||
+ j >= sizeof(temp) - 1)
+ {
+ write_msg(NULL, "could not parse numeric array \"%s\": invalid character in number\n", str);
+ exit_nicely();
+ }
+ temp[j++] = s;
+ }
+ }
+
+ while (argNum < arraysize)
+ array[argNum++] = InvalidOid;
+ }
+
+
+ /*
+ * strInArray:
+ * takes in a string and a string array and the number of elements in the
+ * string array.
+ * returns the index if the string is somewhere in the array, -1 otherwise
+ */
+
+ static int
+ strInArray(const char *pattern, char **arr, int arr_size)
+ {
+ int i;
+
+ for (i = 0; i < arr_size; i++)
+ {
+ if (strcmp(pattern, arr[i]) == 0)
+ return i;
+ }
+ return -1;
+ }
+
+
+ /*
+ * Support for simple list operations
+ */
+
+ void
+ simple_oid_list_append(SimpleOidList *list, Oid val)
+ {
+ SimpleOidListCell *cell;
+
+ cell = (SimpleOidListCell *) pg_malloc(sizeof(SimpleOidListCell));
+ cell->next = NULL;
+ cell->val = val;
+
+ if (list->tail)
+ list->tail->next = cell;
+ else
+ list->head = cell;
+ list->tail = cell;
+ }
+
+ void
+ simple_string_list_append(SimpleStringList *list, const char *val)
+ {
+ SimpleStringListCell *cell;
+
+ /* this calculation correctly accounts for the null trailing byte */
+ cell = (SimpleStringListCell *)
+ pg_malloc(sizeof(SimpleStringListCell) + strlen(val));
+ cell->next = NULL;
+ strcpy(cell->val, val);
+
+ if (list->tail)
+ list->tail->next = cell;
+ else
+ list->head = cell;
+ list->tail = cell;
+ }
+
+ bool
+ simple_oid_list_member(SimpleOidList *list, Oid val)
+ {
+ SimpleOidListCell *cell;
+
+ for (cell = list->head; cell; cell = cell->next)
+ {
+ if (cell->val == val)
+ return true;
+ }
+ return false;
+ }
+
+ bool
+ simple_string_list_member(SimpleStringList *list, const char *val)
+ {
+ SimpleStringListCell *cell;
+
+ for (cell = list->head; cell; cell = cell->next)
+ {
+ if (strcmp(cell->val, val) == 0)
+ return true;
+ }
+ return false;
+ }
diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c
new file mode 100644
index acce7f8..5cc012d
*** a/src/bin/pg_dump/dumputils.c
--- b/src/bin/pg_dump/dumputils.c
***************
*** 16,21 ****
--- 16,22 ----
#include <ctype.h>
+ #include "common.h"
#include "dumputils.h"
#include "parser/keywords.h"
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
new file mode 100644
index f47af26..8fb8382
*** a/src/bin/pg_dump/pg_backup_archiver.c
--- b/src/bin/pg_dump/pg_backup_archiver.c
***************
*** 21,26 ****
--- 21,27 ----
*/
#include "pg_backup_db.h"
+ #include "common.h"
#include "dumputils.h"
#include <ctype.h>
*************** restore_toc_entry(ArchiveHandle *AH, Toc
*** 541,547 ****
{
ahlog(AH, 1, "connecting to new database \"%s\"\n", te->tag);
_reconnectToDB(AH, te->tag);
! ropt->dbname = strdup(te->tag);
}
}
--- 542,548 ----
{
ahlog(AH, 1, "connecting to new database \"%s\"\n", te->tag);
_reconnectToDB(AH, te->tag);
! ropt->dbname = pg_strdup(te->tag);
}
}
*************** NewRestoreOptions(void)
*** 660,666 ****
{
RestoreOptions *opts;
! opts = (RestoreOptions *) calloc(1, sizeof(RestoreOptions));
/* set any fields that shouldn't default to zeroes */
opts->format = archUnknown;
--- 661,667 ----
{
RestoreOptions *opts;
! opts = (RestoreOptions *) pg_calloc(1, sizeof(RestoreOptions));
/* set any fields that shouldn't default to zeroes */
opts->format = archUnknown;
*************** ArchiveEntry(Archive *AHX,
*** 759,767 ****
ArchiveHandle *AH = (ArchiveHandle *) AHX;
TocEntry *newToc;
! newToc = (TocEntry *) calloc(1, sizeof(TocEntry));
! if (!newToc)
! die_horribly(AH, modulename, "out of memory\n");
AH->tocCount++;
if (dumpId > AH->maxDumpId)
--- 760,766 ----
ArchiveHandle *AH = (ArchiveHandle *) AHX;
TocEntry *newToc;
! newToc = (TocEntry *) pg_calloc(1, sizeof(TocEntry));
AH->tocCount++;
if (dumpId > AH->maxDumpId)
*************** ArchiveEntry(Archive *AHX,
*** 776,794 ****
newToc->dumpId = dumpId;
newToc->section = section;
! newToc->tag = strdup(tag);
! newToc->namespace = namespace ? strdup(namespace) : NULL;
! newToc->tablespace = tablespace ? strdup(tablespace) : NULL;
! newToc->owner = strdup(owner);
newToc->withOids = withOids;
! newToc->desc = strdup(desc);
! newToc->defn = strdup(defn);
! newToc->dropStmt = strdup(dropStmt);
! newToc->copyStmt = copyStmt ? strdup(copyStmt) : NULL;
if (nDeps > 0)
{
! newToc->dependencies = (DumpId *) malloc(nDeps * sizeof(DumpId));
memcpy(newToc->dependencies, deps, nDeps * sizeof(DumpId));
newToc->nDeps = nDeps;
}
--- 775,793 ----
newToc->dumpId = dumpId;
newToc->section = section;
! newToc->tag = pg_strdup(tag);
! newToc->namespace = namespace ? pg_strdup(namespace) : NULL;
! newToc->tablespace = tablespace ? pg_strdup(tablespace) : NULL;
! newToc->owner = pg_strdup(owner);
newToc->withOids = withOids;
! newToc->desc = pg_strdup(desc);
! newToc->defn = pg_strdup(defn);
! newToc->dropStmt = pg_strdup(dropStmt);
! newToc->copyStmt = copyStmt ? pg_strdup(copyStmt) : NULL;
if (nDeps > 0)
{
! newToc->dependencies = (DumpId *) pg_malloc(nDeps * sizeof(DumpId));
memcpy(newToc->dependencies, deps, nDeps * sizeof(DumpId));
newToc->nDeps = nDeps;
}
*************** SortTocFromFile(Archive *AHX, RestoreOpt
*** 1032,1038 ****
bool incomplete_line;
/* Allocate space for the 'wanted' array, and init it */
! ropt->idWanted = (bool *) malloc(sizeof(bool) * AH->maxDumpId);
memset(ropt->idWanted, 0, sizeof(bool) * AH->maxDumpId);
/* Setup the file */
--- 1031,1037 ----
bool incomplete_line;
/* Allocate space for the 'wanted' array, and init it */
! ropt->idWanted = (bool *) pg_malloc(sizeof(bool) * AH->maxDumpId);
memset(ropt->idWanted, 0, sizeof(bool) * AH->maxDumpId);
/* Setup the file */
*************** InitDummyWantedList(Archive *AHX, Restor
*** 1120,1126 ****
ArchiveHandle *AH = (ArchiveHandle *) AHX;
/* Allocate space for the 'wanted' array, and init it to 1's */
! ropt->idWanted = (bool *) malloc(sizeof(bool) * AH->maxDumpId);
memset(ropt->idWanted, 1, sizeof(bool) * AH->maxDumpId);
}
--- 1119,1125 ----
ArchiveHandle *AH = (ArchiveHandle *) AHX;
/* Allocate space for the 'wanted' array, and init it to 1's */
! ropt->idWanted = (bool *) pg_malloc(sizeof(bool) * AH->maxDumpId);
memset(ropt->idWanted, 1, sizeof(bool) * AH->maxDumpId);
}
*************** archprintf(Archive *AH, const char *fmt,
*** 1155,1163 ****
if (p != NULL)
free(p);
bSize *= 2;
! p = (char *) malloc(bSize);
! if (p == NULL)
! exit_horribly(AH, modulename, "out of memory\n");
va_start(ap, fmt);
cnt = vsnprintf(p, bSize, fmt, ap);
va_end(ap);
--- 1154,1160 ----
if (p != NULL)
free(p);
bSize *= 2;
! p = (char *) pg_malloc(bSize);
va_start(ap, fmt);
cnt = vsnprintf(p, bSize, fmt, ap);
va_end(ap);
*************** ahprintf(ArchiveHandle *AH, const char *
*** 1286,1294 ****
if (p != NULL)
free(p);
bSize *= 2;
! p = (char *) malloc(bSize);
! if (p == NULL)
! die_horribly(AH, modulename, "out of memory\n");
va_start(ap, fmt);
cnt = vsnprintf(p, bSize, fmt, ap);
va_end(ap);
--- 1283,1289 ----
if (p != NULL)
free(p);
bSize *= 2;
! p = (char *) pg_malloc(bSize);
va_start(ap, fmt);
cnt = vsnprintf(p, bSize, fmt, ap);
va_end(ap);
*************** ReadStr(ArchiveHandle *AH)
*** 1756,1765 ****
buf = NULL;
else
{
! buf = (char *) malloc(l + 1);
! if (!buf)
! die_horribly(AH, modulename, "out of memory\n");
!
if ((*AH->ReadBufPtr) (AH, (void *) buf, l) != l)
die_horribly(AH, modulename, "unexpected end of file\n");
--- 1751,1757 ----
buf = NULL;
else
{
! buf = (char *) pg_malloc(l + 1);
if ((*AH->ReadBufPtr) (AH, (void *) buf, l) != l)
die_horribly(AH, modulename, "unexpected end of file\n");
*************** _discoverArchiveFormat(ArchiveHandle *AH
*** 1785,1791 ****
free(AH->lookahead);
AH->lookaheadSize = 512;
! AH->lookahead = calloc(1, 512);
AH->lookaheadLen = 0;
AH->lookaheadPos = 0;
--- 1777,1783 ----
free(AH->lookahead);
AH->lookaheadSize = 512;
! AH->lookahead = pg_calloc(1, 512);
AH->lookaheadLen = 0;
AH->lookaheadPos = 0;
*************** _allocAH(const char *FileSpec, const Arc
*** 1950,1958 ****
write_msg(modulename, "allocating AH for %s, format %d\n", FileSpec, fmt);
#endif
! AH = (ArchiveHandle *) calloc(1, sizeof(ArchiveHandle));
! if (!AH)
! die_horribly(AH, modulename, "out of memory\n");
/* AH->debugLevel = 100; */
--- 1942,1948 ----
write_msg(modulename, "allocating AH for %s, format %d\n", FileSpec, fmt);
#endif
! AH = (ArchiveHandle *) pg_calloc(1, sizeof(ArchiveHandle));
/* AH->debugLevel = 100; */
*************** _allocAH(const char *FileSpec, const Arc
*** 1979,1990 ****
AH->offSize = sizeof(pgoff_t);
if (FileSpec)
{
! AH->fSpec = strdup(FileSpec);
/*
* Not used; maybe later....
*
! * AH->workDir = strdup(FileSpec); for(i=strlen(FileSpec) ; i > 0 ;
* i--) if (AH->workDir[i-1] == '/')
*/
}
--- 1969,1980 ----
AH->offSize = sizeof(pgoff_t);
if (FileSpec)
{
! AH->fSpec = pg_strdup(FileSpec);
/*
* Not used; maybe later....
*
! * AH->workDir = pg_strdup(FileSpec); for(i=strlen(FileSpec) ; i > 0 ;
* i--) if (AH->workDir[i-1] == '/')
*/
}
*************** _allocAH(const char *FileSpec, const Arc
*** 1996,2004 ****
AH->currTablespace = NULL; /* ditto */
AH->currWithOids = -1; /* force SET */
! AH->toc = (TocEntry *) calloc(1, sizeof(TocEntry));
! if (!AH->toc)
! die_horribly(AH, modulename, "out of memory\n");
AH->toc->next = AH->toc;
AH->toc->prev = AH->toc;
--- 1986,1992 ----
AH->currTablespace = NULL; /* ditto */
AH->currWithOids = -1; /* force SET */
! AH->toc = (TocEntry *) pg_calloc(1, sizeof(TocEntry));
AH->toc->next = AH->toc;
AH->toc->prev = AH->toc;
*************** ReadToc(ArchiveHandle *AH)
*** 2169,2175 ****
for (i = 0; i < AH->tocCount; i++)
{
! te = (TocEntry *) calloc(1, sizeof(TocEntry));
te->dumpId = ReadInt(AH);
if (te->dumpId > AH->maxDumpId)
--- 2157,2163 ----
for (i = 0; i < AH->tocCount; i++)
{
! te = (TocEntry *) pg_calloc(1, sizeof(TocEntry));
te->dumpId = ReadInt(AH);
if (te->dumpId > AH->maxDumpId)
*************** ReadToc(ArchiveHandle *AH)
*** 2255,2261 ****
if (AH->version >= K_VERS_1_5)
{
depSize = 100;
! deps = (DumpId *) malloc(sizeof(DumpId) * depSize);
depIdx = 0;
for (;;)
{
--- 2243,2249 ----
if (AH->version >= K_VERS_1_5)
{
depSize = 100;
! deps = (DumpId *) pg_malloc(sizeof(DumpId) * depSize);
depIdx = 0;
for (;;)
{
*************** static void
*** 2315,2321 ****
processEncodingEntry(ArchiveHandle *AH, TocEntry *te)
{
/* te->defn should have the form SET client_encoding = 'foo'; */
! char *defn = strdup(te->defn);
char *ptr1;
char *ptr2 = NULL;
int encoding;
--- 2303,2309 ----
processEncodingEntry(ArchiveHandle *AH, TocEntry *te)
{
/* te->defn should have the form SET client_encoding = 'foo'; */
! char *defn = pg_strdup(te->defn);
char *ptr1;
char *ptr2 = NULL;
int encoding;
*************** _becomeUser(ArchiveHandle *AH, const cha
*** 2660,2666 ****
*/
if (AH->currUser)
free(AH->currUser);
! AH->currUser = strdup(user);
}
/*
--- 2648,2654 ----
*/
if (AH->currUser)
free(AH->currUser);
! AH->currUser = pg_strdup(user);
}
/*
*************** _selectOutputSchema(ArchiveHandle *AH, c
*** 2729,2735 ****
if (AH->currSchema)
free(AH->currSchema);
! AH->currSchema = strdup(schemaName);
destroyPQExpBuffer(qry);
}
--- 2717,2723 ----
if (AH->currSchema)
free(AH->currSchema);
! AH->currSchema = pg_strdup(schemaName);
destroyPQExpBuffer(qry);
}
*************** _selectTablespace(ArchiveHandle *AH, con
*** 2790,2796 ****
if (AH->currTablespace)
free(AH->currTablespace);
! AH->currTablespace = strdup(want);
destroyPQExpBuffer(qry);
}
--- 2778,2784 ----
if (AH->currTablespace)
free(AH->currTablespace);
! AH->currTablespace = pg_strdup(want);
destroyPQExpBuffer(qry);
}
*************** _getObjectDescription(PQExpBuffer buf, T
*** 2872,2878 ****
strcmp(type, "OPERATOR FAMILY") == 0)
{
/* Chop "DROP " off the front and make a modifiable copy */
! char *first = strdup(te->dropStmt + 5);
char *last;
/* point to last character in string */
--- 2860,2866 ----
strcmp(type, "OPERATOR FAMILY") == 0)
{
/* Chop "DROP " off the front and make a modifiable copy */
! char *first = pg_strdup(te->dropStmt + 5);
char *last;
/* point to last character in string */
*************** restore_toc_entries_parallel(ArchiveHand
*** 3279,3285 ****
ahlog(AH, 2, "entering restore_toc_entries_parallel\n");
! slots = (ParallelSlot *) calloc(sizeof(ParallelSlot), n_slots);
/* Adjust dependency information */
fix_dependencies(AH);
--- 3267,3273 ----
ahlog(AH, 2, "entering restore_toc_entries_parallel\n");
! slots = (ParallelSlot *) pg_calloc(sizeof(ParallelSlot), n_slots);
/* Adjust dependency information */
fix_dependencies(AH);
*************** restore_toc_entries_parallel(ArchiveHand
*** 3431,3437 ****
par_list_remove(next_work_item);
/* this memory is dealloced in mark_work_done() */
! args = malloc(sizeof(RestoreArgs));
args->AH = CloneArchive(AH);
args->te = next_work_item;
--- 3419,3425 ----
par_list_remove(next_work_item);
/* this memory is dealloced in mark_work_done() */
! args = pg_malloc(sizeof(RestoreArgs));
args->AH = CloneArchive(AH);
args->te = next_work_item;
*************** reap_child(ParallelSlot *slots, int n_sl
*** 3550,3556 ****
/* first time around only, make space for handles to listen on */
if (handles == NULL)
! handles = (HANDLE *) calloc(sizeof(HANDLE), n_slots);
/* set up list of handles to listen to */
for (snum = 0, tnum = 0; snum < n_slots; snum++)
--- 3538,3544 ----
/* first time around only, make space for handles to listen on */
if (handles == NULL)
! handles = (HANDLE *) pg_calloc(sizeof(HANDLE), n_slots);
/* set up list of handles to listen to */
for (snum = 0, tnum = 0; snum < n_slots; snum++)
*************** fix_dependencies(ArchiveHandle *AH)
*** 3898,3904 ****
* the TOC items are marked as not being in any parallel-processing list.
*/
maxDumpId = AH->maxDumpId;
! tocsByDumpId = (TocEntry **) calloc(maxDumpId, sizeof(TocEntry *));
for (te = AH->toc->next; te != AH->toc; te = te->next)
{
tocsByDumpId[te->dumpId - 1] = te;
--- 3886,3892 ----
* the TOC items are marked as not being in any parallel-processing list.
*/
maxDumpId = AH->maxDumpId;
! tocsByDumpId = (TocEntry **) pg_calloc(maxDumpId, sizeof(TocEntry *));
for (te = AH->toc->next; te != AH->toc; te = te->next)
{
tocsByDumpId[te->dumpId - 1] = te;
*************** fix_dependencies(ArchiveHandle *AH)
*** 3958,3964 ****
{
if (strcmp(te2->desc, "BLOBS") == 0)
{
! te->dependencies = (DumpId *) malloc(sizeof(DumpId));
te->dependencies[0] = te2->dumpId;
te->nDeps++;
te->depCount++;
--- 3946,3952 ----
{
if (strcmp(te2->desc, "BLOBS") == 0)
{
! te->dependencies = (DumpId *) pg_malloc(sizeof(DumpId));
te->dependencies[0] = te2->dumpId;
te->nDeps++;
te->depCount++;
*************** fix_dependencies(ArchiveHandle *AH)
*** 4000,4006 ****
for (te = AH->toc->next; te != AH->toc; te = te->next)
{
if (te->nRevDeps > 0)
! te->revDeps = (DumpId *) malloc(te->nRevDeps * sizeof(DumpId));
te->nRevDeps = 0;
}
--- 3988,3994 ----
for (te = AH->toc->next; te != AH->toc; te = te->next)
{
if (te->nRevDeps > 0)
! te->revDeps = (DumpId *) pg_malloc(te->nRevDeps * sizeof(DumpId));
te->nRevDeps = 0;
}
*************** identify_locking_dependencies(TocEntry *
*** 4092,4098 ****
* that all the entry types we are interested in here are POST_DATA, so
* they will all have been changed this way.)
*/
! lockids = (DumpId *) malloc(te->nDeps * sizeof(DumpId));
nlockids = 0;
for (i = 0; i < te->nDeps; i++)
{
--- 4080,4086 ----
* that all the entry types we are interested in here are POST_DATA, so
* they will all have been changed this way.)
*/
! lockids = (DumpId *) pg_malloc(te->nDeps * sizeof(DumpId));
nlockids = 0;
for (i = 0; i < te->nDeps; i++)
{
*************** CloneArchive(ArchiveHandle *AH)
*** 4204,4212 ****
ArchiveHandle *clone;
/* Make a "flat" copy */
! clone = (ArchiveHandle *) malloc(sizeof(ArchiveHandle));
! if (clone == NULL)
! die_horribly(AH, modulename, "out of memory\n");
memcpy(clone, AH, sizeof(ArchiveHandle));
/* Handle format-independent fields ... none at the moment */
--- 4192,4198 ----
ArchiveHandle *clone;
/* Make a "flat" copy */
! clone = (ArchiveHandle *) pg_malloc(sizeof(ArchiveHandle));
memcpy(clone, AH, sizeof(ArchiveHandle));
/* Handle format-independent fields ... none at the moment */
*************** CloneArchive(ArchiveHandle *AH)
*** 4220,4226 ****
/* savedPassword must be local in case we change it while connecting */
if (clone->savedPassword)
! clone->savedPassword = strdup(clone->savedPassword);
/* clone has its own error count, too */
clone->public.n_errors = 0;
--- 4206,4212 ----
/* savedPassword must be local in case we change it while connecting */
if (clone->savedPassword)
! clone->savedPassword = pg_strdup(clone->savedPassword);
/* clone has its own error count, too */
clone->public.n_errors = 0;
diff --git a/src/bin/pg_dump/pg_backup_custom.c b/src/bin/pg_dump/pg_backup_custom.c
new file mode 100644
index 55ff39a..bfdf482
*** a/src/bin/pg_dump/pg_backup_custom.c
--- b/src/bin/pg_dump/pg_backup_custom.c
***************
*** 25,30 ****
--- 25,31 ----
*/
#include "compress_io.h"
+ #include "common.h"
/*--------
* Routines in the format interface
*************** InitArchiveFmt_Custom(ArchiveHandle *AH)
*** 126,141 ****
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");
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");
ctx->filePos = 0;
--- 127,138 ----
AH->DeClonePtr = _DeClone;
/* Set up a private area. */
! ctx = (lclContext *) pg_calloc(1, sizeof(lclContext));
AH->formatData = (void *) ctx;
/* Initialize LO buffering */
AH->lo_buf_size = LOBBUFSIZE;
! AH->lo_buf = (void *) pg_malloc(LOBBUFSIZE);
ctx->filePos = 0;
*************** _ArchiveEntry(ArchiveHandle *AH, TocEntr
*** 199,205 ****
{
lclTocEntry *ctx;
! ctx = (lclTocEntry *) calloc(1, sizeof(lclTocEntry));
if (te->dataDumper)
ctx->dataState = K_OFFSET_POS_NOT_SET;
else
--- 196,202 ----
{
lclTocEntry *ctx;
! ctx = (lclTocEntry *) pg_calloc(1, sizeof(lclTocEntry));
if (te->dataDumper)
ctx->dataState = K_OFFSET_POS_NOT_SET;
else
*************** _ReadExtraToc(ArchiveHandle *AH, TocEntr
*** 240,246 ****
if (ctx == NULL)
{
! ctx = (lclTocEntry *) calloc(1, sizeof(lclTocEntry));
te->formatData = (void *) ctx;
}
--- 237,243 ----
if (ctx == NULL)
{
! ctx = (lclTocEntry *) pg_calloc(1, sizeof(lclTocEntry));
te->formatData = (void *) ctx;
}
*************** _skipData(ArchiveHandle *AH)
*** 566,572 ****
{
if (buf)
free(buf);
! buf = (char *) malloc(blkLen);
buflen = blkLen;
}
cnt = fread(buf, 1, blkLen, AH->FH);
--- 563,569 ----
{
if (buf)
free(buf);
! buf = (char *) pg_malloc(blkLen);
buflen = blkLen;
}
cnt = fread(buf, 1, blkLen, AH->FH);
*************** _Clone(ArchiveHandle *AH)
*** 774,782 ****
{
lclContext *ctx = (lclContext *) AH->formatData;
! AH->formatData = (lclContext *) malloc(sizeof(lclContext));
! if (AH->formatData == NULL)
! die_horribly(AH, modulename, "out of memory\n");
memcpy(AH->formatData, ctx, sizeof(lclContext));
ctx = (lclContext *) AH->formatData;
--- 771,777 ----
{
lclContext *ctx = (lclContext *) AH->formatData;
! AH->formatData = (lclContext *) pg_malloc(sizeof(lclContext));
memcpy(AH->formatData, ctx, sizeof(lclContext));
ctx = (lclContext *) AH->formatData;
*************** _CustomReadFunc(ArchiveHandle *AH, char
*** 901,909 ****
if (blkLen > *buflen)
{
free(*buf);
! *buf = (char *) malloc(blkLen);
! if (!(*buf))
! die_horribly(AH, modulename, "out of memory\n");
*buflen = blkLen;
}
--- 896,902 ----
if (blkLen > *buflen)
{
free(*buf);
! *buf = (char *) pg_malloc(blkLen);
*buflen = blkLen;
}
diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c
new file mode 100644
index 600728d..a58eb2d
*** a/src/bin/pg_dump/pg_backup_db.c
--- b/src/bin/pg_dump/pg_backup_db.c
***************
*** 11,16 ****
--- 11,17 ----
*/
#include "pg_backup_db.h"
+ #include "common.h"
#include "dumputils.h"
#include <unistd.h>
*************** _check_database_version(ArchiveHandle *A
*** 55,61 ****
remoteversion = _parse_version(AH, remoteversion_str);
! AH->public.remoteVersionStr = strdup(remoteversion_str);
AH->public.remoteVersion = remoteversion;
if (!AH->archiveRemoteVersion)
AH->archiveRemoteVersion = AH->public.remoteVersionStr;
--- 56,62 ----
remoteversion = _parse_version(AH, remoteversion_str);
! AH->public.remoteVersionStr = pg_strdup(remoteversion_str);
AH->public.remoteVersion = remoteversion;
if (!AH->archiveRemoteVersion)
AH->archiveRemoteVersion = AH->public.remoteVersionStr;
*************** _connectDB(ArchiveHandle *AH, const char
*** 150,160 ****
do
{
#define PARAMS_ARRAY_SIZE 7
! const char **keywords = malloc(PARAMS_ARRAY_SIZE * sizeof(*keywords));
! const char **values = malloc(PARAMS_ARRAY_SIZE * sizeof(*values));
!
! if (!keywords || !values)
! die_horribly(AH, modulename, "out of memory\n");
keywords[0] = "host";
values[0] = PQhost(AH->connection);
--- 151,158 ----
do
{
#define PARAMS_ARRAY_SIZE 7
! const char **keywords = pg_malloc(PARAMS_ARRAY_SIZE * sizeof(*keywords));
! const char **values = pg_malloc(PARAMS_ARRAY_SIZE * sizeof(*values));
keywords[0] = "host";
values[0] = PQhost(AH->connection);
*************** ConnectDatabase(Archive *AHX,
*** 257,267 ****
do
{
#define PARAMS_ARRAY_SIZE 7
! const char **keywords = malloc(PARAMS_ARRAY_SIZE * sizeof(*keywords));
! const char **values = malloc(PARAMS_ARRAY_SIZE * sizeof(*values));
!
! if (!keywords || !values)
! die_horribly(AH, modulename, "out of memory\n");
keywords[0] = "host";
values[0] = pghost;
--- 255,262 ----
do
{
#define PARAMS_ARRAY_SIZE 7
! const char **keywords = pg_malloc(PARAMS_ARRAY_SIZE * sizeof(*keywords));
! const char **values = pg_malloc(PARAMS_ARRAY_SIZE * sizeof(*values));
keywords[0] = "host";
values[0] = pghost;
*************** ExecuteSqlCommandBuf(ArchiveHandle *AH,
*** 397,406 ****
ExecuteSqlCommand(AH, buf, "could not execute query");
else
{
! char *str = (char *) malloc(bufLen + 1);
- if (!str)
- die_horribly(AH, modulename, "out of memory\n");
memcpy(str, buf, bufLen);
str[bufLen] = '\0';
ExecuteSqlCommand(AH, str, "could not execute query");
--- 392,399 ----
ExecuteSqlCommand(AH, buf, "could not execute query");
else
{
! char *str = (char *) pg_malloc(bufLen + 1);
memcpy(str, buf, bufLen);
str[bufLen] = '\0';
ExecuteSqlCommand(AH, str, "could not execute query");
diff --git a/src/bin/pg_dump/pg_backup_directory.c b/src/bin/pg_dump/pg_backup_directory.c
new file mode 100644
index 2e110ac..4f9fcc2
*** a/src/bin/pg_dump/pg_backup_directory.c
--- b/src/bin/pg_dump/pg_backup_directory.c
***************
*** 34,39 ****
--- 34,40 ----
*/
#include "compress_io.h"
+ #include "common.h"
#include <dirent.h>
#include <sys/stat.h>
*************** InitArchiveFmt_Directory(ArchiveHandle *
*** 125,133 ****
AH->DeClonePtr = NULL;
/* Set up our private context */
! ctx = (lclContext *) calloc(1, sizeof(lclContext));
! if (ctx == NULL)
! die_horribly(AH, modulename, "out of memory\n");
AH->formatData = (void *) ctx;
ctx->dataFH = NULL;
--- 126,132 ----
AH->DeClonePtr = NULL;
/* Set up our private context */
! ctx = (lclContext *) pg_calloc(1, sizeof(lclContext));
AH->formatData = (void *) ctx;
ctx->dataFH = NULL;
*************** InitArchiveFmt_Directory(ArchiveHandle *
*** 135,143 ****
/* 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");
/*
* Now open the TOC file
--- 134,140 ----
/* Initialize LO buffering */
AH->lo_buf_size = LOBBUFSIZE;
! AH->lo_buf = (void *) pg_malloc(LOBBUFSIZE);
/*
* Now open the TOC file
*************** _ArchiveEntry(ArchiveHandle *AH, TocEntr
*** 196,211 ****
lclTocEntry *tctx;
char fn[MAXPGPATH];
! tctx = (lclTocEntry *) calloc(1, sizeof(lclTocEntry));
! if (!tctx)
! die_horribly(AH, modulename, "out of memory\n");
if (te->dataDumper)
{
snprintf(fn, MAXPGPATH, "%d.dat", te->dumpId);
! tctx->filename = strdup(fn);
}
else if (strcmp(te->desc, "BLOBS") == 0)
! tctx->filename = strdup("blobs.toc");
else
tctx->filename = NULL;
--- 193,206 ----
lclTocEntry *tctx;
char fn[MAXPGPATH];
! tctx = (lclTocEntry *) pg_calloc(1, sizeof(lclTocEntry));
if (te->dataDumper)
{
snprintf(fn, MAXPGPATH, "%d.dat", te->dumpId);
! tctx->filename = pg_strdup(fn);
}
else if (strcmp(te->desc, "BLOBS") == 0)
! tctx->filename = pg_strdup("blobs.toc");
else
tctx->filename = NULL;
*************** _ReadExtraToc(ArchiveHandle *AH, TocEntr
*** 247,255 ****
if (tctx == NULL)
{
! tctx = (lclTocEntry *) calloc(1, sizeof(lclTocEntry));
! if (!tctx)
! die_horribly(AH, modulename, "out of memory\n");
te->formatData = (void *) tctx;
}
--- 242,248 ----
if (tctx == NULL)
{
! tctx = (lclTocEntry *) pg_calloc(1, sizeof(lclTocEntry));
te->formatData = (void *) tctx;
}
*************** _PrintFileData(ArchiveHandle *AH, char *
*** 355,363 ****
die_horribly(AH, modulename, "could not open input file \"%s\": %s\n",
filename, strerror(errno));
! buf = malloc(ZLIB_OUT_SIZE);
! if (buf == NULL)
! die_horribly(NULL, modulename, "out of memory\n");
buflen = ZLIB_OUT_SIZE;
while ((cnt = cfread(buf, buflen, cfp)))
--- 348,354 ----
die_horribly(AH, modulename, "could not open input file \"%s\": %s\n",
filename, strerror(errno));
! buf = pg_malloc(ZLIB_OUT_SIZE);
buflen = ZLIB_OUT_SIZE;
while ((cnt = cfread(buf, buflen, cfp)))
diff --git a/src/bin/pg_dump/pg_backup_files.c b/src/bin/pg_dump/pg_backup_files.c
new file mode 100644
index afd53bf..76366e1
*** a/src/bin/pg_dump/pg_backup_files.c
--- b/src/bin/pg_dump/pg_backup_files.c
***************
*** 26,31 ****
--- 26,32 ----
*/
#include "pg_backup_archiver.h"
+ #include "common.h"
static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te);
static void _StartData(ArchiveHandle *AH, TocEntry *te);
*************** InitArchiveFmt_Files(ArchiveHandle *AH)
*** 103,117 ****
/*
* Set up some special context used in compressing data.
*/
! ctx = (lclContext *) calloc(1, sizeof(lclContext));
AH->formatData = (void *) ctx;
ctx->filePos = 0;
/* 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");
/*
* Now open the TOC file
--- 104,116 ----
/*
* Set up some special context used in compressing data.
*/
! ctx = (lclContext *) pg_calloc(1, sizeof(lclContext));
AH->formatData = (void *) ctx;
ctx->filePos = 0;
/* Initialize LO buffering */
AH->lo_buf_size = LOBBUFSIZE;
! AH->lo_buf = (void *) pg_malloc(LOBBUFSIZE);
/*
* Now open the TOC file
*************** _ArchiveEntry(ArchiveHandle *AH, TocEntr
*** 183,189 ****
lclTocEntry *ctx;
char fn[K_STD_BUF_SIZE];
! ctx = (lclTocEntry *) calloc(1, sizeof(lclTocEntry));
if (te->dataDumper)
{
#ifdef HAVE_LIBZ
--- 182,188 ----
lclTocEntry *ctx;
char fn[K_STD_BUF_SIZE];
! ctx = (lclTocEntry *) pg_calloc(1, sizeof(lclTocEntry));
if (te->dataDumper)
{
#ifdef HAVE_LIBZ
*************** _ArchiveEntry(ArchiveHandle *AH, TocEntr
*** 194,200 ****
#else
sprintf(fn, "%d.dat", te->dumpId);
#endif
! ctx->filename = strdup(fn);
}
else
{
--- 193,199 ----
#else
sprintf(fn, "%d.dat", te->dumpId);
#endif
! ctx->filename = pg_strdup(fn);
}
else
{
*************** _ReadExtraToc(ArchiveHandle *AH, TocEntr
*** 222,228 ****
if (ctx == NULL)
{
! ctx = (lclTocEntry *) calloc(1, sizeof(lclTocEntry));
te->formatData = (void *) ctx;
}
--- 221,227 ----
if (ctx == NULL)
{
! ctx = (lclTocEntry *) pg_calloc(1, sizeof(lclTocEntry));
te->formatData = (void *) ctx;
}
diff --git a/src/bin/pg_dump/pg_backup_null.c b/src/bin/pg_dump/pg_backup_null.c
new file mode 100644
index bf1e6e6..252e7a4
*** a/src/bin/pg_dump/pg_backup_null.c
--- b/src/bin/pg_dump/pg_backup_null.c
***************
*** 23,28 ****
--- 23,29 ----
*/
#include "pg_backup_archiver.h"
+ #include "common.h"
#include "dumputils.h"
#include <unistd.h> /* for dup */
*************** InitArchiveFmt_Null(ArchiveHandle *AH)
*** 67,75 ****
/* Initialize LO buffering */
AH->lo_buf_size = LOBBUFSIZE;
! AH->lo_buf = (void *) malloc(LOBBUFSIZE);
! if (AH->lo_buf == NULL)
! die_horribly(AH, NULL, "out of memory\n");
/*
* Now prevent reading...
--- 68,74 ----
/* Initialize LO buffering */
AH->lo_buf_size = LOBBUFSIZE;
! AH->lo_buf = (void *) pg_malloc(LOBBUFSIZE);
/*
* Now prevent reading...
diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c
new file mode 100644
index 4642132..94133cf
*** a/src/bin/pg_dump/pg_backup_tar.c
--- b/src/bin/pg_dump/pg_backup_tar.c
***************
*** 28,33 ****
--- 28,34 ----
#include "pg_backup.h"
#include "pg_backup_archiver.h"
#include "pg_backup_tar.h"
+ #include "common.h"
#include <sys/stat.h>
#include <ctype.h>
*************** InitArchiveFmt_Tar(ArchiveHandle *AH)
*** 159,174 ****
/*
* Set up some special context used in compressing data.
*/
! 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);
! if (AH->lo_buf == NULL)
! die_horribly(AH, modulename, "out of memory\n");
/*
* Now open the tar file, and load the TOC if we're in read mode.
--- 160,173 ----
/*
* Set up some special context used in compressing data.
*/
! ctx = (lclContext *) pg_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 *) pg_malloc(LOBBUFSIZE);
/*
* Now open the tar file, and load the TOC if we're in read mode.
*************** _ArchiveEntry(ArchiveHandle *AH, TocEntr
*** 267,273 ****
lclTocEntry *ctx;
char fn[K_STD_BUF_SIZE];
! ctx = (lclTocEntry *) calloc(1, sizeof(lclTocEntry));
if (te->dataDumper != NULL)
{
#ifdef HAVE_LIBZ
--- 266,272 ----
lclTocEntry *ctx;
char fn[K_STD_BUF_SIZE];
! ctx = (lclTocEntry *) pg_calloc(1, sizeof(lclTocEntry));
if (te->dataDumper != NULL)
{
#ifdef HAVE_LIBZ
*************** _ArchiveEntry(ArchiveHandle *AH, TocEntr
*** 278,284 ****
#else
sprintf(fn, "%d.dat", te->dumpId);
#endif
! ctx->filename = strdup(fn);
}
else
{
--- 277,283 ----
#else
sprintf(fn, "%d.dat", te->dumpId);
#endif
! ctx->filename = pg_strdup(fn);
}
else
{
*************** _ReadExtraToc(ArchiveHandle *AH, TocEntr
*** 306,312 ****
if (ctx == NULL)
{
! ctx = (lclTocEntry *) calloc(1, sizeof(lclTocEntry));
te->formatData = (void *) ctx;
}
--- 305,311 ----
if (ctx == NULL)
{
! ctx = (lclTocEntry *) pg_calloc(1, sizeof(lclTocEntry));
te->formatData = (void *) ctx;
}
*************** tarOpen(ArchiveHandle *AH, const char *f
*** 379,385 ****
}
else
{
! tm = calloc(1, sizeof(TAR_MEMBER));
#ifndef WIN32
tm->tmpFH = tmpfile();
--- 378,384 ----
}
else
{
! tm = pg_calloc(1, sizeof(TAR_MEMBER));
#ifndef WIN32
tm->tmpFH = tmpfile();
*************** tarOpen(ArchiveHandle *AH, const char *f
*** 432,438 ****
#endif
tm->AH = AH;
! tm->targetFile = strdup(filename);
}
tm->mode = mode;
--- 431,437 ----
#endif
tm->AH = AH;
! tm->targetFile = pg_strdup(filename);
}
tm->mode = mode;
*************** _PrintTocData(ArchiveHandle *AH, TocEntr
*** 665,671 ****
ahprintf(AH, "\\.\n");
/* Get a copy of the COPY statement and clean it up */
! tmpCopy = strdup(te->copyStmt);
for (i = 0; i < strlen(tmpCopy); i++)
tmpCopy[i] = pg_tolower((unsigned char) tmpCopy[i]);
--- 664,670 ----
ahprintf(AH, "\\.\n");
/* Get a copy of the COPY statement and clean it up */
! tmpCopy = pg_strdup(te->copyStmt);
for (i = 0; i < strlen(tmpCopy); i++)
tmpCopy[i] = pg_tolower((unsigned char) tmpCopy[i]);
*************** tarPrintf(ArchiveHandle *AH, TAR_MEMBER
*** 1010,1018 ****
if (p != NULL)
free(p);
bSize *= 2;
! p = (char *) malloc(bSize);
! if (p == NULL)
! die_horribly(AH, modulename, "out of memory\n");
va_start(ap, fmt);
cnt = vsnprintf(p, bSize, fmt, ap);
va_end(ap);
--- 1009,1015 ----
if (p != NULL)
free(p);
bSize *= 2;
! p = (char *) pg_malloc(bSize);
va_start(ap, fmt);
cnt = vsnprintf(p, bSize, fmt, ap);
va_end(ap);
*************** static TAR_MEMBER *
*** 1125,1131 ****
_tarPositionTo(ArchiveHandle *AH, const char *filename)
{
lclContext *ctx = (lclContext *) AH->formatData;
! TAR_MEMBER *th = calloc(1, sizeof(TAR_MEMBER));
char c;
char header[512];
size_t i,
--- 1122,1128 ----
_tarPositionTo(ArchiveHandle *AH, const char *filename)
{
lclContext *ctx = (lclContext *) AH->formatData;
! TAR_MEMBER *th = pg_calloc(1, sizeof(TAR_MEMBER));
char c;
char header[512];
size_t i,
*************** _tarGetHeader(ArchiveHandle *AH, TAR_MEM
*** 1295,1301 ****
tag, sum, chk, buf);
}
! th->targetFile = strdup(tag);
th->fileLen = len;
return 1;
--- 1292,1298 ----
tag, sum, chk, buf);
}
! th->targetFile = pg_strdup(tag);
th->fileLen = len;
return 1;
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
new file mode 100644
index 973f0b3..096db6d
*** a/src/bin/pg_dump/pg_dump.c
--- b/src/bin/pg_dump/pg_dump.c
***************
*** 58,63 ****
--- 58,64 ----
#include "libpq/libpq-fs.h"
#include "pg_backup_archiver.h"
+ #include "common.h"
#include "dumputils.h"
extern char *optarg;
*************** main(int argc, char **argv)
*** 439,445 ****
break;
case 'S': /* Username for superuser in plain text output */
! outputSuperuser = strdup(optarg);
break;
case 't': /* include table(s) */
--- 440,446 ----
break;
case 'S': /* Username for superuser in plain text output */
! outputSuperuser = pg_strdup(optarg);
break;
case 't': /* include table(s) */
*************** makeTableDataInfo(TableInfo *tbinfo, boo
*** 1586,1592 ****
{
TableDataInfo *tdinfo;
! tdinfo = (TableDataInfo *) malloc(sizeof(TableDataInfo));
tdinfo->dobj.objType = DO_TABLE_DATA;
--- 1587,1593 ----
{
TableDataInfo *tdinfo;
! tdinfo = (TableDataInfo *) pg_malloc(sizeof(TableDataInfo));
tdinfo->dobj.objType = DO_TABLE_DATA;
*************** getBlobs(Archive *AH)
*** 2182,2188 ****
/*
* Each large object has its own BLOB archive entry.
*/
! binfo = (BlobInfo *) malloc(ntups * sizeof(BlobInfo));
for (i = 0; i < ntups; i++)
{
--- 2183,2189 ----
/*
* Each large object has its own BLOB archive entry.
*/
! binfo = (BlobInfo *) pg_malloc(ntups * sizeof(BlobInfo));
for (i = 0; i < ntups; i++)
{
*************** getBlobs(Archive *AH)
*** 2191,2203 ****
binfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, 0));
AssignDumpId(&binfo[i].dobj);
! binfo[i].dobj.name = strdup(PQgetvalue(res, i, 0));
if (!PQgetisnull(res, i, 1))
! binfo[i].rolname = strdup(PQgetvalue(res, i, 1));
else
binfo[i].rolname = "";
if (!PQgetisnull(res, i, 2))
! binfo[i].blobacl = strdup(PQgetvalue(res, i, 2));
else
binfo[i].blobacl = NULL;
}
--- 2192,2204 ----
binfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, 0));
AssignDumpId(&binfo[i].dobj);
! binfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, 0));
if (!PQgetisnull(res, i, 1))
! binfo[i].rolname = pg_strdup(PQgetvalue(res, i, 1));
else
binfo[i].rolname = "";
if (!PQgetisnull(res, i, 2))
! binfo[i].blobacl = pg_strdup(PQgetvalue(res, i, 2));
else
binfo[i].blobacl = NULL;
}
*************** getBlobs(Archive *AH)
*** 2206,2216 ****
* If we have any large objects, a "BLOBS" archive entry is needed.
* This is just a placeholder for sorting; it carries no data now.
*/
! bdata = (DumpableObject *) malloc(sizeof(DumpableObject));
bdata->objType = DO_BLOB_DATA;
bdata->catId = nilCatalogId;
AssignDumpId(bdata);
! bdata->name = strdup("BLOBS");
}
PQclear(res);
--- 2207,2217 ----
* If we have any large objects, a "BLOBS" archive entry is needed.
* This is just a placeholder for sorting; it carries no data now.
*/
! bdata = (DumpableObject *) pg_malloc(sizeof(DumpableObject));
bdata->objType = DO_BLOB_DATA;
bdata->catId = nilCatalogId;
AssignDumpId(bdata);
! bdata->name = pg_strdup("BLOBS");
}
PQclear(res);
*************** getNamespaces(int *numNamespaces)
*** 2609,2623 ****
*/
if (g_fout->remoteVersion < 70300)
{
! nsinfo = (NamespaceInfo *) malloc(2 * sizeof(NamespaceInfo));
nsinfo[0].dobj.objType = DO_NAMESPACE;
nsinfo[0].dobj.catId.tableoid = 0;
nsinfo[0].dobj.catId.oid = 0;
AssignDumpId(&nsinfo[0].dobj);
! nsinfo[0].dobj.name = strdup("public");
! nsinfo[0].rolname = strdup("");
! nsinfo[0].nspacl = strdup("");
selectDumpableNamespace(&nsinfo[0]);
--- 2610,2624 ----
*/
if (g_fout->remoteVersion < 70300)
{
! nsinfo = (NamespaceInfo *) pg_malloc(2 * sizeof(NamespaceInfo));
nsinfo[0].dobj.objType = DO_NAMESPACE;
nsinfo[0].dobj.catId.tableoid = 0;
nsinfo[0].dobj.catId.oid = 0;
AssignDumpId(&nsinfo[0].dobj);
! nsinfo[0].dobj.name = pg_strdup("public");
! nsinfo[0].rolname = pg_strdup("");
! nsinfo[0].nspacl = pg_strdup("");
selectDumpableNamespace(&nsinfo[0]);
*************** getNamespaces(int *numNamespaces)
*** 2625,2633 ****
nsinfo[1].dobj.catId.tableoid = 0;
nsinfo[1].dobj.catId.oid = 1;
AssignDumpId(&nsinfo[1].dobj);
! nsinfo[1].dobj.name = strdup("pg_catalog");
! nsinfo[1].rolname = strdup("");
! nsinfo[1].nspacl = strdup("");
selectDumpableNamespace(&nsinfo[1]);
--- 2626,2634 ----
nsinfo[1].dobj.catId.tableoid = 0;
nsinfo[1].dobj.catId.oid = 1;
AssignDumpId(&nsinfo[1].dobj);
! nsinfo[1].dobj.name = pg_strdup("pg_catalog");
! nsinfo[1].rolname = pg_strdup("");
! nsinfo[1].nspacl = pg_strdup("");
selectDumpableNamespace(&nsinfo[1]);
*************** getNamespaces(int *numNamespaces)
*** 2656,2662 ****
ntups = PQntuples(res);
! nsinfo = (NamespaceInfo *) malloc(ntups * sizeof(NamespaceInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 2657,2663 ----
ntups = PQntuples(res);
! nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getNamespaces(int *numNamespaces)
*** 2670,2678 ****
nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&nsinfo[i].dobj);
! nsinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_nspname));
! nsinfo[i].rolname = strdup(PQgetvalue(res, i, i_rolname));
! nsinfo[i].nspacl = strdup(PQgetvalue(res, i, i_nspacl));
/* Decide whether to dump this namespace */
selectDumpableNamespace(&nsinfo[i]);
--- 2671,2679 ----
nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&nsinfo[i].dobj);
! nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
! nsinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
! nsinfo[i].nspacl = pg_strdup(PQgetvalue(res, i, i_nspacl));
/* Decide whether to dump this namespace */
selectDumpableNamespace(&nsinfo[i]);
*************** getExtensions(int *numExtensions)
*** 2777,2783 ****
ntups = PQntuples(res);
! extinfo = (ExtensionInfo *) malloc(ntups * sizeof(ExtensionInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 2778,2784 ----
ntups = PQntuples(res);
! extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getExtensions(int *numExtensions)
*** 2794,2805 ****
extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&extinfo[i].dobj);
! extinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_extname));
! extinfo[i].namespace = strdup(PQgetvalue(res, i, i_nspname));
extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
! extinfo[i].extversion = strdup(PQgetvalue(res, i, i_extversion));
! extinfo[i].extconfig = strdup(PQgetvalue(res, i, i_extconfig));
! extinfo[i].extcondition = strdup(PQgetvalue(res, i, i_extcondition));
/* Decide whether we want to dump it */
selectDumpableExtension(&(extinfo[i]));
--- 2795,2806 ----
extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&extinfo[i].dobj);
! extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
! extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
! extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
! extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
! extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
/* Decide whether we want to dump it */
selectDumpableExtension(&(extinfo[i]));
*************** getTypes(int *numTypes)
*** 2930,2936 ****
ntups = PQntuples(res);
! tyinfo = (TypeInfo *) malloc(ntups * sizeof(TypeInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 2931,2937 ----
ntups = PQntuples(res);
! tyinfo = (TypeInfo *) pg_malloc(ntups * sizeof(TypeInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getTypes(int *numTypes)
*** 2952,2961 ****
tyinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
tyinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&tyinfo[i].dobj);
! tyinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_typname));
tyinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_typnamespace)),
tyinfo[i].dobj.catId.oid);
! tyinfo[i].rolname = strdup(PQgetvalue(res, i, i_rolname));
tyinfo[i].typelem = atooid(PQgetvalue(res, i, i_typelem));
tyinfo[i].typrelid = atooid(PQgetvalue(res, i, i_typrelid));
tyinfo[i].typrelkind = *PQgetvalue(res, i, i_typrelkind);
--- 2953,2962 ----
tyinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
tyinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&tyinfo[i].dobj);
! tyinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_typname));
tyinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_typnamespace)),
tyinfo[i].dobj.catId.oid);
! tyinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
tyinfo[i].typelem = atooid(PQgetvalue(res, i, i_typelem));
tyinfo[i].typrelid = atooid(PQgetvalue(res, i, i_typrelid));
tyinfo[i].typrelkind = *PQgetvalue(res, i, i_typrelkind);
*************** getTypes(int *numTypes)
*** 2995,3005 ****
if (tyinfo[i].dobj.dump && (tyinfo[i].typtype == TYPTYPE_BASE ||
tyinfo[i].typtype == TYPTYPE_RANGE))
{
! stinfo = (ShellTypeInfo *) malloc(sizeof(ShellTypeInfo));
stinfo->dobj.objType = DO_SHELL_TYPE;
stinfo->dobj.catId = nilCatalogId;
AssignDumpId(&stinfo->dobj);
! stinfo->dobj.name = strdup(tyinfo[i].dobj.name);
stinfo->dobj.namespace = tyinfo[i].dobj.namespace;
stinfo->baseType = &(tyinfo[i]);
tyinfo[i].shellType = stinfo;
--- 2996,3006 ----
if (tyinfo[i].dobj.dump && (tyinfo[i].typtype == TYPTYPE_BASE ||
tyinfo[i].typtype == TYPTYPE_RANGE))
{
! stinfo = (ShellTypeInfo *) pg_malloc(sizeof(ShellTypeInfo));
stinfo->dobj.objType = DO_SHELL_TYPE;
stinfo->dobj.catId = nilCatalogId;
AssignDumpId(&stinfo->dobj);
! stinfo->dobj.name = pg_strdup(tyinfo[i].dobj.name);
stinfo->dobj.namespace = tyinfo[i].dobj.namespace;
stinfo->baseType = &(tyinfo[i]);
tyinfo[i].shellType = stinfo;
*************** getOperators(int *numOprs)
*** 3134,3140 ****
ntups = PQntuples(res);
*numOprs = ntups;
! oprinfo = (OprInfo *) malloc(ntups * sizeof(OprInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 3135,3141 ----
ntups = PQntuples(res);
*numOprs = ntups;
! oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getOperators(int *numOprs)
*** 3149,3158 ****
oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&oprinfo[i].dobj);
! oprinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_oprname));
oprinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_oprnamespace)),
oprinfo[i].dobj.catId.oid);
! oprinfo[i].rolname = strdup(PQgetvalue(res, i, i_rolname));
oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
/* Decide whether we want to dump it */
--- 3150,3159 ----
oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&oprinfo[i].dobj);
! oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
oprinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_oprnamespace)),
oprinfo[i].dobj.catId.oid);
! oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
/* Decide whether we want to dump it */
*************** getCollations(int *numCollations)
*** 3218,3224 ****
ntups = PQntuples(res);
*numCollations = ntups;
! collinfo = (CollInfo *) malloc(ntups * sizeof(CollInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 3219,3225 ----
ntups = PQntuples(res);
*numCollations = ntups;
! collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getCollations(int *numCollations)
*** 3232,3241 ****
collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&collinfo[i].dobj);
! collinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_collname));
collinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_collnamespace)),
collinfo[i].dobj.catId.oid);
! collinfo[i].rolname = strdup(PQgetvalue(res, i, i_rolname));
/* Decide whether we want to dump it */
selectDumpableObject(&(collinfo[i].dobj));
--- 3233,3242 ----
collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&collinfo[i].dobj);
! collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
collinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_collnamespace)),
collinfo[i].dobj.catId.oid);
! collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
/* Decide whether we want to dump it */
selectDumpableObject(&(collinfo[i].dobj));
*************** getConversions(int *numConversions)
*** 3296,3302 ****
ntups = PQntuples(res);
*numConversions = ntups;
! convinfo = (ConvInfo *) malloc(ntups * sizeof(ConvInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 3297,3303 ----
ntups = PQntuples(res);
*numConversions = ntups;
! convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getConversions(int *numConversions)
*** 3310,3319 ****
convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&convinfo[i].dobj);
! convinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_conname));
convinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_connamespace)),
convinfo[i].dobj.catId.oid);
! convinfo[i].rolname = strdup(PQgetvalue(res, i, i_rolname));
/* Decide whether we want to dump it */
selectDumpableObject(&(convinfo[i].dobj));
--- 3311,3320 ----
convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&convinfo[i].dobj);
! convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
convinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_connamespace)),
convinfo[i].dobj.catId.oid);
! convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
/* Decide whether we want to dump it */
selectDumpableObject(&(convinfo[i].dobj));
*************** getOpclasses(int *numOpclasses)
*** 3386,3392 ****
ntups = PQntuples(res);
*numOpclasses = ntups;
! opcinfo = (OpclassInfo *) malloc(ntups * sizeof(OpclassInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 3387,3393 ----
ntups = PQntuples(res);
*numOpclasses = ntups;
! opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getOpclasses(int *numOpclasses)
*** 3400,3409 ****
opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&opcinfo[i].dobj);
! opcinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_opcname));
opcinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_opcnamespace)),
opcinfo[i].dobj.catId.oid);
! opcinfo[i].rolname = strdup(PQgetvalue(res, i, i_rolname));
/* Decide whether we want to dump it */
selectDumpableObject(&(opcinfo[i].dobj));
--- 3401,3410 ----
opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&opcinfo[i].dobj);
! opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
opcinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_opcnamespace)),
opcinfo[i].dobj.catId.oid);
! opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
/* Decide whether we want to dump it */
selectDumpableObject(&(opcinfo[i].dobj));
*************** getOpfamilies(int *numOpfamilies)
*** 3473,3479 ****
ntups = PQntuples(res);
*numOpfamilies = ntups;
! opfinfo = (OpfamilyInfo *) malloc(ntups * sizeof(OpfamilyInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 3474,3480 ----
ntups = PQntuples(res);
*numOpfamilies = ntups;
! opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getOpfamilies(int *numOpfamilies)
*** 3487,3496 ****
opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&opfinfo[i].dobj);
! opfinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_opfname));
opfinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_opfnamespace)),
opfinfo[i].dobj.catId.oid);
! opfinfo[i].rolname = strdup(PQgetvalue(res, i, i_rolname));
/* Decide whether we want to dump it */
selectDumpableObject(&(opfinfo[i].dobj));
--- 3488,3497 ----
opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&opfinfo[i].dobj);
! opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
opfinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_opfnamespace)),
opfinfo[i].dobj.catId.oid);
! opfinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
/* Decide whether we want to dump it */
selectDumpableObject(&(opfinfo[i].dobj));
*************** getAggregates(int *numAggs)
*** 3613,3619 ****
ntups = PQntuples(res);
*numAggs = ntups;
! agginfo = (AggInfo *) malloc(ntups * sizeof(AggInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 3614,3620 ----
ntups = PQntuples(res);
*numAggs = ntups;
! agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getAggregates(int *numAggs)
*** 3630,3651 ****
agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&agginfo[i].aggfn.dobj);
! agginfo[i].aggfn.dobj.name = strdup(PQgetvalue(res, i, i_aggname));
agginfo[i].aggfn.dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_aggnamespace)),
agginfo[i].aggfn.dobj.catId.oid);
! agginfo[i].aggfn.rolname = strdup(PQgetvalue(res, i, i_rolname));
if (strlen(agginfo[i].aggfn.rolname) == 0)
write_msg(NULL, "WARNING: owner of aggregate function \"%s\" appears to be invalid\n",
agginfo[i].aggfn.dobj.name);
agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
! agginfo[i].aggfn.proacl = strdup(PQgetvalue(res, i, i_aggacl));
agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
if (agginfo[i].aggfn.nargs == 0)
agginfo[i].aggfn.argtypes = NULL;
else
{
! agginfo[i].aggfn.argtypes = (Oid *) malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
if (g_fout->remoteVersion >= 70300)
parseOidArray(PQgetvalue(res, i, i_proargtypes),
agginfo[i].aggfn.argtypes,
--- 3631,3652 ----
agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&agginfo[i].aggfn.dobj);
! agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
agginfo[i].aggfn.dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_aggnamespace)),
agginfo[i].aggfn.dobj.catId.oid);
! agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
if (strlen(agginfo[i].aggfn.rolname) == 0)
write_msg(NULL, "WARNING: owner of aggregate function \"%s\" appears to be invalid\n",
agginfo[i].aggfn.dobj.name);
agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
! agginfo[i].aggfn.proacl = pg_strdup(PQgetvalue(res, i, i_aggacl));
agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
if (agginfo[i].aggfn.nargs == 0)
agginfo[i].aggfn.argtypes = NULL;
else
{
! agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
if (g_fout->remoteVersion >= 70300)
parseOidArray(PQgetvalue(res, i, i_proargtypes),
agginfo[i].aggfn.argtypes,
*************** getFuncs(int *numFuncs)
*** 3788,3794 ****
*numFuncs = ntups;
! finfo = (FuncInfo *) calloc(ntups, sizeof(FuncInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 3789,3795 ----
*numFuncs = ntups;
! finfo = (FuncInfo *) pg_calloc(ntups, sizeof(FuncInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getFuncs(int *numFuncs)
*** 3807,3826 ****
finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&finfo[i].dobj);
! finfo[i].dobj.name = strdup(PQgetvalue(res, i, i_proname));
finfo[i].dobj.namespace =
findNamespace(atooid(PQgetvalue(res, i, i_pronamespace)),
finfo[i].dobj.catId.oid);
! finfo[i].rolname = strdup(PQgetvalue(res, i, i_rolname));
finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
! finfo[i].proacl = strdup(PQgetvalue(res, i, i_proacl));
finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
if (finfo[i].nargs == 0)
finfo[i].argtypes = NULL;
else
{
! finfo[i].argtypes = (Oid *) malloc(finfo[i].nargs * sizeof(Oid));
parseOidArray(PQgetvalue(res, i, i_proargtypes),
finfo[i].argtypes, finfo[i].nargs);
}
--- 3808,3827 ----
finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&finfo[i].dobj);
! finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
finfo[i].dobj.namespace =
findNamespace(atooid(PQgetvalue(res, i, i_pronamespace)),
finfo[i].dobj.catId.oid);
! finfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
! finfo[i].proacl = pg_strdup(PQgetvalue(res, i, i_proacl));
finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
if (finfo[i].nargs == 0)
finfo[i].argtypes = NULL;
else
{
! finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
parseOidArray(PQgetvalue(res, i, i_proargtypes),
finfo[i].argtypes, finfo[i].nargs);
}
*************** getTables(int *numTables)
*** 4217,4223 ****
* only one, because we don't yet know which tables might be inheritance
* ancestors of the target table.
*/
! tblinfo = (TableInfo *) calloc(ntups, sizeof(TableInfo));
i_reltableoid = PQfnumber(res, "tableoid");
i_reloid = PQfnumber(res, "oid");
--- 4218,4224 ----
* only one, because we don't yet know which tables might be inheritance
* ancestors of the target table.
*/
! tblinfo = (TableInfo *) pg_calloc(ntups, sizeof(TableInfo));
i_reltableoid = PQfnumber(res, "tableoid");
i_reloid = PQfnumber(res, "oid");
*************** getTables(int *numTables)
*** 4263,4273 ****
tblinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_reltableoid));
tblinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_reloid));
AssignDumpId(&tblinfo[i].dobj);
! tblinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_relname));
tblinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_relnamespace)),
tblinfo[i].dobj.catId.oid);
! tblinfo[i].rolname = strdup(PQgetvalue(res, i, i_rolname));
! tblinfo[i].relacl = strdup(PQgetvalue(res, i, i_relacl));
tblinfo[i].relkind = *(PQgetvalue(res, i, i_relkind));
tblinfo[i].relpersistence = *(PQgetvalue(res, i, i_relpersistence));
tblinfo[i].hasindex = (strcmp(PQgetvalue(res, i, i_relhasindex), "t") == 0);
--- 4264,4274 ----
tblinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_reltableoid));
tblinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_reloid));
AssignDumpId(&tblinfo[i].dobj);
! tblinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_relname));
tblinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_relnamespace)),
tblinfo[i].dobj.catId.oid);
! tblinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
! tblinfo[i].relacl = pg_strdup(PQgetvalue(res, i, i_relacl));
tblinfo[i].relkind = *(PQgetvalue(res, i, i_relkind));
tblinfo[i].relpersistence = *(PQgetvalue(res, i, i_relpersistence));
tblinfo[i].hasindex = (strcmp(PQgetvalue(res, i, i_relhasindex), "t") == 0);
*************** getTables(int *numTables)
*** 4280,4286 ****
if (PQgetisnull(res, i, i_reloftype))
tblinfo[i].reloftype = NULL;
else
! tblinfo[i].reloftype = strdup(PQgetvalue(res, i, i_reloftype));
tblinfo[i].ncheck = atoi(PQgetvalue(res, i, i_relchecks));
if (PQgetisnull(res, i, i_owning_tab))
{
--- 4281,4287 ----
if (PQgetisnull(res, i, i_reloftype))
tblinfo[i].reloftype = NULL;
else
! tblinfo[i].reloftype = pg_strdup(PQgetvalue(res, i, i_reloftype));
tblinfo[i].ncheck = atoi(PQgetvalue(res, i, i_relchecks));
if (PQgetisnull(res, i, i_owning_tab))
{
*************** getTables(int *numTables)
*** 4292,4300 ****
tblinfo[i].owning_tab = atooid(PQgetvalue(res, i, i_owning_tab));
tblinfo[i].owning_col = atoi(PQgetvalue(res, i, i_owning_col));
}
! tblinfo[i].reltablespace = strdup(PQgetvalue(res, i, i_reltablespace));
! tblinfo[i].reloptions = strdup(PQgetvalue(res, i, i_reloptions));
! tblinfo[i].toast_reloptions = strdup(PQgetvalue(res, i, i_toastreloptions));
/* other fields were zeroed above */
--- 4293,4301 ----
tblinfo[i].owning_tab = atooid(PQgetvalue(res, i, i_owning_tab));
tblinfo[i].owning_col = atoi(PQgetvalue(res, i, i_owning_col));
}
! tblinfo[i].reltablespace = pg_strdup(PQgetvalue(res, i, i_reltablespace));
! tblinfo[i].reloptions = pg_strdup(PQgetvalue(res, i, i_reloptions));
! tblinfo[i].toast_reloptions = pg_strdup(PQgetvalue(res, i, i_toastreloptions));
/* other fields were zeroed above */
*************** getInherits(int *numInherits)
*** 4408,4414 ****
*numInherits = ntups;
! inhinfo = (InhInfo *) malloc(ntups * sizeof(InhInfo));
i_inhrelid = PQfnumber(res, "inhrelid");
i_inhparent = PQfnumber(res, "inhparent");
--- 4409,4415 ----
*numInherits = ntups;
! inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
i_inhrelid = PQfnumber(res, "inhrelid");
i_inhparent = PQfnumber(res, "inhparent");
*************** getIndexes(TableInfo tblinfo[], int numT
*** 4673,4680 ****
i_tablespace = PQfnumber(res, "tablespace");
i_options = PQfnumber(res, "options");
! indxinfo = (IndxInfo *) malloc(ntups * sizeof(IndxInfo));
! constrinfo = (ConstraintInfo *) malloc(ntups * sizeof(ConstraintInfo));
for (j = 0; j < ntups; j++)
{
--- 4674,4681 ----
i_tablespace = PQfnumber(res, "tablespace");
i_options = PQfnumber(res, "options");
! indxinfo = (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
! constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
for (j = 0; j < ntups; j++)
{
*************** getIndexes(TableInfo tblinfo[], int numT
*** 4684,4696 ****
indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
AssignDumpId(&indxinfo[j].dobj);
! indxinfo[j].dobj.name = strdup(PQgetvalue(res, j, i_indexname));
indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
indxinfo[j].indextable = tbinfo;
! indxinfo[j].indexdef = strdup(PQgetvalue(res, j, i_indexdef));
indxinfo[j].indnkeys = atoi(PQgetvalue(res, j, i_indnkeys));
! indxinfo[j].tablespace = strdup(PQgetvalue(res, j, i_tablespace));
! indxinfo[j].options = strdup(PQgetvalue(res, j, i_options));
/*
* In pre-7.4 releases, indkeys may contain more entries than
--- 4685,4697 ----
indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
AssignDumpId(&indxinfo[j].dobj);
! indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
indxinfo[j].indextable = tbinfo;
! indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
indxinfo[j].indnkeys = atoi(PQgetvalue(res, j, i_indnkeys));
! indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
! indxinfo[j].options = pg_strdup(PQgetvalue(res, j, i_options));
/*
* In pre-7.4 releases, indkeys may contain more entries than
*************** getIndexes(TableInfo tblinfo[], int numT
*** 4701,4707 ****
* have to allocate enough space to keep parseOidArray from
* complaining.
*/
! indxinfo[j].indkeys = (Oid *) malloc(INDEX_MAX_KEYS * sizeof(Oid));
parseOidArray(PQgetvalue(res, j, i_indkey),
indxinfo[j].indkeys, INDEX_MAX_KEYS);
indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
--- 4702,4708 ----
* have to allocate enough space to keep parseOidArray from
* complaining.
*/
! indxinfo[j].indkeys = (Oid *) pg_malloc(INDEX_MAX_KEYS * sizeof(Oid));
parseOidArray(PQgetvalue(res, j, i_indkey),
indxinfo[j].indkeys, INDEX_MAX_KEYS);
indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
*************** getIndexes(TableInfo tblinfo[], int numT
*** 4720,4732 ****
constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
AssignDumpId(&constrinfo[j].dobj);
! constrinfo[j].dobj.name = strdup(PQgetvalue(res, j, i_conname));
constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
constrinfo[j].contable = tbinfo;
constrinfo[j].condomain = NULL;
constrinfo[j].contype = contype;
if (contype == 'x')
! constrinfo[j].condef = strdup(PQgetvalue(res, j, i_condef));
else
constrinfo[j].condef = NULL;
constrinfo[j].confrelid = InvalidOid;
--- 4721,4733 ----
constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
AssignDumpId(&constrinfo[j].dobj);
! constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
constrinfo[j].contable = tbinfo;
constrinfo[j].condomain = NULL;
constrinfo[j].contype = contype;
if (contype == 'x')
! constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
else
constrinfo[j].condef = NULL;
constrinfo[j].confrelid = InvalidOid;
*************** getConstraints(TableInfo tblinfo[], int
*** 4821,4827 ****
i_confrelid = PQfnumber(res, "confrelid");
i_condef = PQfnumber(res, "condef");
! constrinfo = (ConstraintInfo *) malloc(ntups * sizeof(ConstraintInfo));
for (j = 0; j < ntups; j++)
{
--- 4822,4828 ----
i_confrelid = PQfnumber(res, "confrelid");
i_condef = PQfnumber(res, "condef");
! constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
for (j = 0; j < ntups; j++)
{
*************** getConstraints(TableInfo tblinfo[], int
*** 4829,4840 ****
constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
AssignDumpId(&constrinfo[j].dobj);
! constrinfo[j].dobj.name = strdup(PQgetvalue(res, j, i_conname));
constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
constrinfo[j].contable = tbinfo;
constrinfo[j].condomain = NULL;
constrinfo[j].contype = 'f';
! constrinfo[j].condef = strdup(PQgetvalue(res, j, i_condef));
constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
constrinfo[j].conindex = 0;
constrinfo[j].condeferrable = false;
--- 4830,4841 ----
constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
AssignDumpId(&constrinfo[j].dobj);
! constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
constrinfo[j].contable = tbinfo;
constrinfo[j].condomain = NULL;
constrinfo[j].contype = 'f';
! constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
constrinfo[j].conindex = 0;
constrinfo[j].condeferrable = false;
*************** getDomainConstraints(TypeInfo *tyinfo)
*** 4904,4910 ****
i_conname = PQfnumber(res, "conname");
i_consrc = PQfnumber(res, "consrc");
! constrinfo = (ConstraintInfo *) malloc(ntups * sizeof(ConstraintInfo));
tyinfo->nDomChecks = ntups;
tyinfo->domChecks = constrinfo;
--- 4905,4911 ----
i_conname = PQfnumber(res, "conname");
i_consrc = PQfnumber(res, "consrc");
! constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
tyinfo->nDomChecks = ntups;
tyinfo->domChecks = constrinfo;
*************** getDomainConstraints(TypeInfo *tyinfo)
*** 4915,4926 ****
constrinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
constrinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&constrinfo[i].dobj);
! constrinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_conname));
constrinfo[i].dobj.namespace = tyinfo->dobj.namespace;
constrinfo[i].contable = NULL;
constrinfo[i].condomain = tyinfo;
constrinfo[i].contype = 'c';
! constrinfo[i].condef = strdup(PQgetvalue(res, i, i_consrc));
constrinfo[i].confrelid = InvalidOid;
constrinfo[i].conindex = 0;
constrinfo[i].condeferrable = false;
--- 4916,4927 ----
constrinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
constrinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&constrinfo[i].dobj);
! constrinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
constrinfo[i].dobj.namespace = tyinfo->dobj.namespace;
constrinfo[i].contable = NULL;
constrinfo[i].condomain = tyinfo;
constrinfo[i].contype = 'c';
! constrinfo[i].condef = pg_strdup(PQgetvalue(res, i, i_consrc));
constrinfo[i].confrelid = InvalidOid;
constrinfo[i].conindex = 0;
constrinfo[i].condeferrable = false;
*************** getRules(int *numRules)
*** 5002,5008 ****
*numRules = ntups;
! ruleinfo = (RuleInfo *) malloc(ntups * sizeof(RuleInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 5003,5009 ----
*numRules = ntups;
! ruleinfo = (RuleInfo *) pg_malloc(ntups * sizeof(RuleInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getRules(int *numRules)
*** 5020,5026 ****
ruleinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
ruleinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&ruleinfo[i].dobj);
! ruleinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_rulename));
ruletableoid = atooid(PQgetvalue(res, i, i_ruletable));
ruleinfo[i].ruletable = findTableByOid(ruletableoid);
if (ruleinfo[i].ruletable == NULL)
--- 5021,5027 ----
ruleinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
ruleinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&ruleinfo[i].dobj);
! ruleinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_rulename));
ruletableoid = atooid(PQgetvalue(res, i, i_ruletable));
ruleinfo[i].ruletable = findTableByOid(ruletableoid);
if (ruleinfo[i].ruletable == NULL)
*************** getTriggers(TableInfo tblinfo[], int num
*** 5224,5230 ****
i_tginitdeferred = PQfnumber(res, "tginitdeferred");
i_tgdef = PQfnumber(res, "tgdef");
! tginfo = (TriggerInfo *) malloc(ntups * sizeof(TriggerInfo));
for (j = 0; j < ntups; j++)
{
--- 5225,5231 ----
i_tginitdeferred = PQfnumber(res, "tginitdeferred");
i_tgdef = PQfnumber(res, "tgdef");
! tginfo = (TriggerInfo *) pg_malloc(ntups * sizeof(TriggerInfo));
for (j = 0; j < ntups; j++)
{
*************** getTriggers(TableInfo tblinfo[], int num
*** 5232,5244 ****
tginfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
tginfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
AssignDumpId(&tginfo[j].dobj);
! tginfo[j].dobj.name = strdup(PQgetvalue(res, j, i_tgname));
tginfo[j].dobj.namespace = tbinfo->dobj.namespace;
tginfo[j].tgtable = tbinfo;
tginfo[j].tgenabled = *(PQgetvalue(res, j, i_tgenabled));
if (i_tgdef >= 0)
{
! tginfo[j].tgdef = strdup(PQgetvalue(res, j, i_tgdef));
/* remaining fields are not valid if we have tgdef */
tginfo[j].tgfname = NULL;
--- 5233,5245 ----
tginfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
tginfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
AssignDumpId(&tginfo[j].dobj);
! tginfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_tgname));
tginfo[j].dobj.namespace = tbinfo->dobj.namespace;
tginfo[j].tgtable = tbinfo;
tginfo[j].tgenabled = *(PQgetvalue(res, j, i_tgenabled));
if (i_tgdef >= 0)
{
! tginfo[j].tgdef = pg_strdup(PQgetvalue(res, j, i_tgdef));
/* remaining fields are not valid if we have tgdef */
tginfo[j].tgfname = NULL;
*************** getTriggers(TableInfo tblinfo[], int num
*** 5256,5272 ****
{
tginfo[j].tgdef = NULL;
! tginfo[j].tgfname = strdup(PQgetvalue(res, j, i_tgfname));
tginfo[j].tgtype = atoi(PQgetvalue(res, j, i_tgtype));
tginfo[j].tgnargs = atoi(PQgetvalue(res, j, i_tgnargs));
! tginfo[j].tgargs = strdup(PQgetvalue(res, j, i_tgargs));
tginfo[j].tgisconstraint = *(PQgetvalue(res, j, i_tgisconstraint)) == 't';
tginfo[j].tgdeferrable = *(PQgetvalue(res, j, i_tgdeferrable)) == 't';
tginfo[j].tginitdeferred = *(PQgetvalue(res, j, i_tginitdeferred)) == 't';
if (tginfo[j].tgisconstraint)
{
! tginfo[j].tgconstrname = strdup(PQgetvalue(res, j, i_tgconstrname));
tginfo[j].tgconstrrelid = atooid(PQgetvalue(res, j, i_tgconstrrelid));
if (OidIsValid(tginfo[j].tgconstrrelid))
{
--- 5257,5273 ----
{
tginfo[j].tgdef = NULL;
! tginfo[j].tgfname = pg_strdup(PQgetvalue(res, j, i_tgfname));
tginfo[j].tgtype = atoi(PQgetvalue(res, j, i_tgtype));
tginfo[j].tgnargs = atoi(PQgetvalue(res, j, i_tgnargs));
! tginfo[j].tgargs = pg_strdup(PQgetvalue(res, j, i_tgargs));
tginfo[j].tgisconstraint = *(PQgetvalue(res, j, i_tgisconstraint)) == 't';
tginfo[j].tgdeferrable = *(PQgetvalue(res, j, i_tgdeferrable)) == 't';
tginfo[j].tginitdeferred = *(PQgetvalue(res, j, i_tginitdeferred)) == 't';
if (tginfo[j].tgisconstraint)
{
! tginfo[j].tgconstrname = pg_strdup(PQgetvalue(res, j, i_tgconstrname));
tginfo[j].tgconstrrelid = atooid(PQgetvalue(res, j, i_tgconstrrelid));
if (OidIsValid(tginfo[j].tgconstrrelid))
{
*************** getTriggers(TableInfo tblinfo[], int num
*** 5277,5283 ****
tginfo[j].tgconstrrelid);
exit_nicely();
}
! tginfo[j].tgconstrrelname = strdup(PQgetvalue(res, j, i_tgconstrrelname));
}
else
tginfo[j].tgconstrrelname = NULL;
--- 5278,5284 ----
tginfo[j].tgconstrrelid);
exit_nicely();
}
! tginfo[j].tgconstrrelname = pg_strdup(PQgetvalue(res, j, i_tgconstrrelname));
}
else
tginfo[j].tgconstrrelname = NULL;
*************** getProcLangs(int *numProcLangs)
*** 5394,5400 ****
*numProcLangs = ntups;
! planginfo = (ProcLangInfo *) malloc(ntups * sizeof(ProcLangInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 5395,5401 ----
*numProcLangs = ntups;
! planginfo = (ProcLangInfo *) pg_malloc(ntups * sizeof(ProcLangInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getProcLangs(int *numProcLangs)
*** 5414,5420 ****
planginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&planginfo[i].dobj);
! planginfo[i].dobj.name = strdup(PQgetvalue(res, i, i_lanname));
planginfo[i].lanpltrusted = *(PQgetvalue(res, i, i_lanpltrusted)) == 't';
planginfo[i].lanplcallfoid = atooid(PQgetvalue(res, i, i_lanplcallfoid));
if (i_laninline >= 0)
--- 5415,5421 ----
planginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&planginfo[i].dobj);
! planginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_lanname));
planginfo[i].lanpltrusted = *(PQgetvalue(res, i, i_lanpltrusted)) == 't';
planginfo[i].lanplcallfoid = atooid(PQgetvalue(res, i, i_lanplcallfoid));
if (i_laninline >= 0)
*************** getProcLangs(int *numProcLangs)
*** 5426,5438 ****
else
planginfo[i].lanvalidator = InvalidOid;
if (i_lanacl >= 0)
! planginfo[i].lanacl = strdup(PQgetvalue(res, i, i_lanacl));
else
! planginfo[i].lanacl = strdup("{=U}");
if (i_lanowner >= 0)
! planginfo[i].lanowner = strdup(PQgetvalue(res, i, i_lanowner));
else
! planginfo[i].lanowner = strdup("");
if (g_fout->remoteVersion < 70300)
{
--- 5427,5439 ----
else
planginfo[i].lanvalidator = InvalidOid;
if (i_lanacl >= 0)
! planginfo[i].lanacl = pg_strdup(PQgetvalue(res, i, i_lanacl));
else
! planginfo[i].lanacl = pg_strdup("{=U}");
if (i_lanowner >= 0)
! planginfo[i].lanowner = pg_strdup(PQgetvalue(res, i, i_lanowner));
else
! planginfo[i].lanowner = pg_strdup("");
if (g_fout->remoteVersion < 70300)
{
*************** getCasts(int *numCasts)
*** 5515,5521 ****
*numCasts = ntups;
! castinfo = (CastInfo *) malloc(ntups * sizeof(CastInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 5516,5522 ----
*numCasts = ntups;
! castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getTableAttrs(TableInfo *tblinfo, int nu
*** 5797,5820 ****
i_attfdwoptions = PQfnumber(res, "attfdwoptions");
tbinfo->numatts = ntups;
! tbinfo->attnames = (char **) malloc(ntups * sizeof(char *));
! tbinfo->atttypnames = (char **) malloc(ntups * sizeof(char *));
! tbinfo->atttypmod = (int *) malloc(ntups * sizeof(int));
! tbinfo->attstattarget = (int *) malloc(ntups * sizeof(int));
! tbinfo->attstorage = (char *) malloc(ntups * sizeof(char));
! tbinfo->typstorage = (char *) malloc(ntups * sizeof(char));
! tbinfo->attisdropped = (bool *) malloc(ntups * sizeof(bool));
! tbinfo->attlen = (int *) malloc(ntups * sizeof(int));
! tbinfo->attalign = (char *) malloc(ntups * sizeof(char));
! tbinfo->attislocal = (bool *) malloc(ntups * sizeof(bool));
! tbinfo->notnull = (bool *) malloc(ntups * sizeof(bool));
! tbinfo->attrdefs = (AttrDefInfo **) malloc(ntups * sizeof(AttrDefInfo *));
! tbinfo->attoptions = (char **) malloc(ntups * sizeof(char *));
! tbinfo->attcollation = (Oid *) malloc(ntups * sizeof(Oid));
! tbinfo->attfdwoptions = (char **) malloc(ntups * sizeof(char *));
! tbinfo->inhAttrs = (bool *) malloc(ntups * sizeof(bool));
! tbinfo->inhAttrDef = (bool *) malloc(ntups * sizeof(bool));
! tbinfo->inhNotNull = (bool *) malloc(ntups * sizeof(bool));
hasdefaults = false;
for (j = 0; j < ntups; j++)
--- 5798,5821 ----
i_attfdwoptions = PQfnumber(res, "attfdwoptions");
tbinfo->numatts = ntups;
! tbinfo->attnames = (char **) pg_malloc(ntups * sizeof(char *));
! tbinfo->atttypnames = (char **) pg_malloc(ntups * sizeof(char *));
! tbinfo->atttypmod = (int *) pg_malloc(ntups * sizeof(int));
! tbinfo->attstattarget = (int *) pg_malloc(ntups * sizeof(int));
! tbinfo->attstorage = (char *) pg_malloc(ntups * sizeof(char));
! tbinfo->typstorage = (char *) pg_malloc(ntups * sizeof(char));
! tbinfo->attisdropped = (bool *) pg_malloc(ntups * sizeof(bool));
! tbinfo->attlen = (int *) pg_malloc(ntups * sizeof(int));
! tbinfo->attalign = (char *) pg_malloc(ntups * sizeof(char));
! tbinfo->attislocal = (bool *) pg_malloc(ntups * sizeof(bool));
! tbinfo->notnull = (bool *) pg_malloc(ntups * sizeof(bool));
! tbinfo->attrdefs = (AttrDefInfo **) pg_malloc(ntups * sizeof(AttrDefInfo *));
! tbinfo->attoptions = (char **) pg_malloc(ntups * sizeof(char *));
! tbinfo->attcollation = (Oid *) pg_malloc(ntups * sizeof(Oid));
! tbinfo->attfdwoptions = (char **) pg_malloc(ntups * sizeof(char *));
! tbinfo->inhAttrs = (bool *) pg_malloc(ntups * sizeof(bool));
! tbinfo->inhAttrDef = (bool *) pg_malloc(ntups * sizeof(bool));
! tbinfo->inhNotNull = (bool *) pg_malloc(ntups * sizeof(bool));
hasdefaults = false;
for (j = 0; j < ntups; j++)
*************** getTableAttrs(TableInfo *tblinfo, int nu
*** 5825,5832 ****
tbinfo->dobj.name);
exit_nicely();
}
! tbinfo->attnames[j] = strdup(PQgetvalue(res, j, i_attname));
! tbinfo->atttypnames[j] = strdup(PQgetvalue(res, j, i_atttypname));
tbinfo->atttypmod[j] = atoi(PQgetvalue(res, j, i_atttypmod));
tbinfo->attstattarget[j] = atoi(PQgetvalue(res, j, i_attstattarget));
tbinfo->attstorage[j] = *(PQgetvalue(res, j, i_attstorage));
--- 5826,5833 ----
tbinfo->dobj.name);
exit_nicely();
}
! tbinfo->attnames[j] = pg_strdup(PQgetvalue(res, j, i_attname));
! tbinfo->atttypnames[j] = pg_strdup(PQgetvalue(res, j, i_atttypname));
tbinfo->atttypmod[j] = atoi(PQgetvalue(res, j, i_atttypmod));
tbinfo->attstattarget[j] = atoi(PQgetvalue(res, j, i_attstattarget));
tbinfo->attstorage[j] = *(PQgetvalue(res, j, i_attstorage));
*************** getTableAttrs(TableInfo *tblinfo, int nu
*** 5836,5844 ****
tbinfo->attalign[j] = *(PQgetvalue(res, j, i_attalign));
tbinfo->attislocal[j] = (PQgetvalue(res, j, i_attislocal)[0] == 't');
tbinfo->notnull[j] = (PQgetvalue(res, j, i_attnotnull)[0] == 't');
! tbinfo->attoptions[j] = strdup(PQgetvalue(res, j, i_attoptions));
tbinfo->attcollation[j] = atooid(PQgetvalue(res, j, i_attcollation));
! tbinfo->attfdwoptions[j] = strdup(PQgetvalue(res, j, i_attfdwoptions));
tbinfo->attrdefs[j] = NULL; /* fix below */
if (PQgetvalue(res, j, i_atthasdef)[0] == 't')
hasdefaults = true;
--- 5837,5845 ----
tbinfo->attalign[j] = *(PQgetvalue(res, j, i_attalign));
tbinfo->attislocal[j] = (PQgetvalue(res, j, i_attislocal)[0] == 't');
tbinfo->notnull[j] = (PQgetvalue(res, j, i_attnotnull)[0] == 't');
! tbinfo->attoptions[j] = pg_strdup(PQgetvalue(res, j, i_attoptions));
tbinfo->attcollation[j] = atooid(PQgetvalue(res, j, i_attcollation));
! tbinfo->attfdwoptions[j] = pg_strdup(PQgetvalue(res, j, i_attfdwoptions));
tbinfo->attrdefs[j] = NULL; /* fix below */
if (PQgetvalue(res, j, i_atthasdef)[0] == 't')
hasdefaults = true;
*************** getTableAttrs(TableInfo *tblinfo, int nu
*** 5902,5908 ****
check_sql_result(res, g_conn, q->data, PGRES_TUPLES_OK);
numDefaults = PQntuples(res);
! attrdefs = (AttrDefInfo *) malloc(numDefaults * sizeof(AttrDefInfo));
for (j = 0; j < numDefaults; j++)
{
--- 5903,5909 ----
check_sql_result(res, g_conn, q->data, PGRES_TUPLES_OK);
numDefaults = PQntuples(res);
! attrdefs = (AttrDefInfo *) pg_malloc(numDefaults * sizeof(AttrDefInfo));
for (j = 0; j < numDefaults; j++)
{
*************** getTableAttrs(TableInfo *tblinfo, int nu
*** 5914,5922 ****
AssignDumpId(&attrdefs[j].dobj);
attrdefs[j].adtable = tbinfo;
attrdefs[j].adnum = adnum = atoi(PQgetvalue(res, j, 2));
! attrdefs[j].adef_expr = strdup(PQgetvalue(res, j, 3));
! attrdefs[j].dobj.name = strdup(tbinfo->dobj.name);
attrdefs[j].dobj.namespace = tbinfo->dobj.namespace;
attrdefs[j].dobj.dump = tbinfo->dobj.dump;
--- 5915,5923 ----
AssignDumpId(&attrdefs[j].dobj);
attrdefs[j].adtable = tbinfo;
attrdefs[j].adnum = adnum = atoi(PQgetvalue(res, j, 2));
! attrdefs[j].adef_expr = pg_strdup(PQgetvalue(res, j, 3));
! attrdefs[j].dobj.name = pg_strdup(tbinfo->dobj.name);
attrdefs[j].dobj.namespace = tbinfo->dobj.namespace;
attrdefs[j].dobj.dump = tbinfo->dobj.dump;
*************** getTableAttrs(TableInfo *tblinfo, int nu
*** 6050,6056 ****
exit_nicely();
}
! constrs = (ConstraintInfo *) malloc(numConstrs * sizeof(ConstraintInfo));
tbinfo->checkexprs = constrs;
for (j = 0; j < numConstrs; j++)
--- 6051,6057 ----
exit_nicely();
}
! constrs = (ConstraintInfo *) pg_malloc(numConstrs * sizeof(ConstraintInfo));
tbinfo->checkexprs = constrs;
for (j = 0; j < numConstrs; j++)
*************** getTableAttrs(TableInfo *tblinfo, int nu
*** 6059,6070 ****
constrs[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, 0));
constrs[j].dobj.catId.oid = atooid(PQgetvalue(res, j, 1));
AssignDumpId(&constrs[j].dobj);
! constrs[j].dobj.name = strdup(PQgetvalue(res, j, 2));
constrs[j].dobj.namespace = tbinfo->dobj.namespace;
constrs[j].contable = tbinfo;
constrs[j].condomain = NULL;
constrs[j].contype = 'c';
! constrs[j].condef = strdup(PQgetvalue(res, j, 3));
constrs[j].confrelid = InvalidOid;
constrs[j].conindex = 0;
constrs[j].condeferrable = false;
--- 6060,6071 ----
constrs[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, 0));
constrs[j].dobj.catId.oid = atooid(PQgetvalue(res, j, 1));
AssignDumpId(&constrs[j].dobj);
! constrs[j].dobj.name = pg_strdup(PQgetvalue(res, j, 2));
constrs[j].dobj.namespace = tbinfo->dobj.namespace;
constrs[j].contable = tbinfo;
constrs[j].condomain = NULL;
constrs[j].contype = 'c';
! constrs[j].condef = pg_strdup(PQgetvalue(res, j, 3));
constrs[j].confrelid = InvalidOid;
constrs[j].conindex = 0;
constrs[j].condeferrable = false;
*************** getTSParsers(int *numTSParsers)
*** 6148,6154 ****
ntups = PQntuples(res);
*numTSParsers = ntups;
! prsinfo = (TSParserInfo *) malloc(ntups * sizeof(TSParserInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 6149,6155 ----
ntups = PQntuples(res);
*numTSParsers = ntups;
! prsinfo = (TSParserInfo *) pg_malloc(ntups * sizeof(TSParserInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getTSParsers(int *numTSParsers)
*** 6166,6172 ****
prsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
prsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&prsinfo[i].dobj);
! prsinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_prsname));
prsinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_prsnamespace)),
prsinfo[i].dobj.catId.oid);
prsinfo[i].prsstart = atooid(PQgetvalue(res, i, i_prsstart));
--- 6167,6173 ----
prsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
prsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&prsinfo[i].dobj);
! prsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_prsname));
prsinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_prsnamespace)),
prsinfo[i].dobj.catId.oid);
prsinfo[i].prsstart = atooid(PQgetvalue(res, i, i_prsstart));
*************** getTSDictionaries(int *numTSDicts)
*** 6231,6237 ****
ntups = PQntuples(res);
*numTSDicts = ntups;
! dictinfo = (TSDictInfo *) malloc(ntups * sizeof(TSDictInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 6232,6238 ----
ntups = PQntuples(res);
*numTSDicts = ntups;
! dictinfo = (TSDictInfo *) pg_malloc(ntups * sizeof(TSDictInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getTSDictionaries(int *numTSDicts)
*** 6247,6261 ****
dictinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
dictinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&dictinfo[i].dobj);
! dictinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_dictname));
dictinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_dictnamespace)),
dictinfo[i].dobj.catId.oid);
! dictinfo[i].rolname = strdup(PQgetvalue(res, i, i_rolname));
dictinfo[i].dicttemplate = atooid(PQgetvalue(res, i, i_dicttemplate));
if (PQgetisnull(res, i, i_dictinitoption))
dictinfo[i].dictinitoption = NULL;
else
! dictinfo[i].dictinitoption = strdup(PQgetvalue(res, i, i_dictinitoption));
/* Decide whether we want to dump it */
selectDumpableObject(&(dictinfo[i].dobj));
--- 6248,6262 ----
dictinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
dictinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&dictinfo[i].dobj);
! dictinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_dictname));
dictinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_dictnamespace)),
dictinfo[i].dobj.catId.oid);
! dictinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
dictinfo[i].dicttemplate = atooid(PQgetvalue(res, i, i_dicttemplate));
if (PQgetisnull(res, i, i_dictinitoption))
dictinfo[i].dictinitoption = NULL;
else
! dictinfo[i].dictinitoption = pg_strdup(PQgetvalue(res, i, i_dictinitoption));
/* Decide whether we want to dump it */
selectDumpableObject(&(dictinfo[i].dobj));
*************** getTSTemplates(int *numTSTemplates)
*** 6310,6316 ****
ntups = PQntuples(res);
*numTSTemplates = ntups;
! tmplinfo = (TSTemplateInfo *) malloc(ntups * sizeof(TSTemplateInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 6311,6317 ----
ntups = PQntuples(res);
*numTSTemplates = ntups;
! tmplinfo = (TSTemplateInfo *) pg_malloc(ntups * sizeof(TSTemplateInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getTSTemplates(int *numTSTemplates)
*** 6325,6331 ****
tmplinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
tmplinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&tmplinfo[i].dobj);
! tmplinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_tmplname));
tmplinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_tmplnamespace)),
tmplinfo[i].dobj.catId.oid);
tmplinfo[i].tmplinit = atooid(PQgetvalue(res, i, i_tmplinit));
--- 6326,6332 ----
tmplinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
tmplinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&tmplinfo[i].dobj);
! tmplinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_tmplname));
tmplinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_tmplnamespace)),
tmplinfo[i].dobj.catId.oid);
tmplinfo[i].tmplinit = atooid(PQgetvalue(res, i, i_tmplinit));
*************** getTSConfigurations(int *numTSConfigs)
*** 6385,6391 ****
ntups = PQntuples(res);
*numTSConfigs = ntups;
! cfginfo = (TSConfigInfo *) malloc(ntups * sizeof(TSConfigInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 6386,6392 ----
ntups = PQntuples(res);
*numTSConfigs = ntups;
! cfginfo = (TSConfigInfo *) pg_malloc(ntups * sizeof(TSConfigInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getTSConfigurations(int *numTSConfigs)
*** 6400,6409 ****
cfginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
cfginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&cfginfo[i].dobj);
! cfginfo[i].dobj.name = strdup(PQgetvalue(res, i, i_cfgname));
cfginfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_cfgnamespace)),
cfginfo[i].dobj.catId.oid);
! cfginfo[i].rolname = strdup(PQgetvalue(res, i, i_rolname));
cfginfo[i].cfgparser = atooid(PQgetvalue(res, i, i_cfgparser));
/* Decide whether we want to dump it */
--- 6401,6410 ----
cfginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
cfginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&cfginfo[i].dobj);
! cfginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_cfgname));
cfginfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_cfgnamespace)),
cfginfo[i].dobj.catId.oid);
! cfginfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
cfginfo[i].cfgparser = atooid(PQgetvalue(res, i, i_cfgparser));
/* Decide whether we want to dump it */
*************** getForeignDataWrappers(int *numForeignDa
*** 6484,6490 ****
ntups = PQntuples(res);
*numForeignDataWrappers = ntups;
! fdwinfo = (FdwInfo *) malloc(ntups * sizeof(FdwInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 6485,6491 ----
ntups = PQntuples(res);
*numForeignDataWrappers = ntups;
! fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getForeignDataWrappers(int *numForeignDa
*** 6501,6513 ****
fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&fdwinfo[i].dobj);
! fdwinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_fdwname));
fdwinfo[i].dobj.namespace = NULL;
! fdwinfo[i].rolname = strdup(PQgetvalue(res, i, i_rolname));
! fdwinfo[i].fdwhandler = strdup(PQgetvalue(res, i, i_fdwhandler));
! fdwinfo[i].fdwvalidator = strdup(PQgetvalue(res, i, i_fdwvalidator));
! fdwinfo[i].fdwoptions = strdup(PQgetvalue(res, i, i_fdwoptions));
! fdwinfo[i].fdwacl = strdup(PQgetvalue(res, i, i_fdwacl));
/* Decide whether we want to dump it */
selectDumpableObject(&(fdwinfo[i].dobj));
--- 6502,6514 ----
fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&fdwinfo[i].dobj);
! fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
fdwinfo[i].dobj.namespace = NULL;
! fdwinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
! fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
! fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
! fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
! fdwinfo[i].fdwacl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
/* Decide whether we want to dump it */
selectDumpableObject(&(fdwinfo[i].dobj));
*************** getForeignServers(int *numForeignServers
*** 6571,6577 ****
ntups = PQntuples(res);
*numForeignServers = ntups;
! srvinfo = (ForeignServerInfo *) malloc(ntups * sizeof(ForeignServerInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
--- 6572,6578 ----
ntups = PQntuples(res);
*numForeignServers = ntups;
! srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
*************** getForeignServers(int *numForeignServers
*** 6589,6602 ****
srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&srvinfo[i].dobj);
! srvinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_srvname));
srvinfo[i].dobj.namespace = NULL;
! srvinfo[i].rolname = strdup(PQgetvalue(res, i, i_rolname));
srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
! srvinfo[i].srvtype = strdup(PQgetvalue(res, i, i_srvtype));
! srvinfo[i].srvversion = strdup(PQgetvalue(res, i, i_srvversion));
! srvinfo[i].srvoptions = strdup(PQgetvalue(res, i, i_srvoptions));
! srvinfo[i].srvacl = strdup(PQgetvalue(res, i, i_srvacl));
/* Decide whether we want to dump it */
selectDumpableObject(&(srvinfo[i].dobj));
--- 6590,6603 ----
srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&srvinfo[i].dobj);
! srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
srvinfo[i].dobj.namespace = NULL;
! srvinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
! srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
! srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
! srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
! srvinfo[i].srvacl = pg_strdup(PQgetvalue(res, i, i_srvacl));
/* Decide whether we want to dump it */
selectDumpableObject(&(srvinfo[i].dobj));
*************** getDefaultACLs(int *numDefaultACLs)
*** 6656,6662 ****
ntups = PQntuples(res);
*numDefaultACLs = ntups;
! daclinfo = (DefaultACLInfo *) malloc(ntups * sizeof(DefaultACLInfo));
i_oid = PQfnumber(res, "oid");
i_tableoid = PQfnumber(res, "tableoid");
--- 6657,6663 ----
ntups = PQntuples(res);
*numDefaultACLs = ntups;
! daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
i_oid = PQfnumber(res, "oid");
i_tableoid = PQfnumber(res, "tableoid");
*************** getDefaultACLs(int *numDefaultACLs)
*** 6674,6680 ****
daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&daclinfo[i].dobj);
/* cheesy ... is it worth coming up with a better object name? */
! daclinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_defaclobjtype));
if (nspid != InvalidOid)
daclinfo[i].dobj.namespace = findNamespace(nspid,
--- 6675,6681 ----
daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&daclinfo[i].dobj);
/* cheesy ... is it worth coming up with a better object name? */
! daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
if (nspid != InvalidOid)
daclinfo[i].dobj.namespace = findNamespace(nspid,
*************** getDefaultACLs(int *numDefaultACLs)
*** 6682,6690 ****
else
daclinfo[i].dobj.namespace = NULL;
! daclinfo[i].defaclrole = strdup(PQgetvalue(res, i, i_defaclrole));
daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
! daclinfo[i].defaclacl = strdup(PQgetvalue(res, i, i_defaclacl));
/* Decide whether we want to dump it */
selectDumpableDefaultACL(&(daclinfo[i]));
--- 6683,6691 ----
else
daclinfo[i].dobj.namespace = NULL;
! daclinfo[i].defaclrole = pg_strdup(PQgetvalue(res, i, i_defaclrole));
daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
! daclinfo[i].defaclacl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
/* Decide whether we want to dump it */
selectDumpableDefaultACL(&(daclinfo[i]));
*************** collectComments(Archive *fout, CommentIt
*** 7012,7018 ****
ntups = PQntuples(res);
! comments = (CommentItem *) malloc(ntups * sizeof(CommentItem));
for (i = 0; i < ntups; i++)
{
--- 7013,7019 ----
ntups = PQntuples(res);
! comments = (CommentItem *) pg_malloc(ntups * sizeof(CommentItem));
for (i = 0; i < ntups; i++)
{
*************** dumpNamespace(Archive *fout, NamespaceIn
*** 7165,7171 ****
delq = createPQExpBuffer();
labelq = createPQExpBuffer();
! qnspname = strdup(fmtId(nspinfo->dobj.name));
appendPQExpBuffer(delq, "DROP SCHEMA %s;\n", qnspname);
--- 7166,7172 ----
delq = createPQExpBuffer();
labelq = createPQExpBuffer();
! qnspname = pg_strdup(fmtId(nspinfo->dobj.name));
appendPQExpBuffer(delq, "DROP SCHEMA %s;\n", qnspname);
*************** dumpExtension(Archive *fout, ExtensionIn
*** 7224,7230 ****
delq = createPQExpBuffer();
labelq = createPQExpBuffer();
! qextname = strdup(fmtId(extinfo->dobj.name));
appendPQExpBuffer(delq, "DROP EXTENSION %s;\n", qextname);
--- 7225,7231 ----
delq = createPQExpBuffer();
labelq = createPQExpBuffer();
! qextname = pg_strdup(fmtId(extinfo->dobj.name));
appendPQExpBuffer(delq, "DROP EXTENSION %s;\n", qextname);
*************** dumpProcLang(Archive *fout, ProcLangInfo
*** 8641,8647 ****
delqry = createPQExpBuffer();
labelq = createPQExpBuffer();
! qlanname = strdup(fmtId(plang->dobj.name));
/*
* If dumping a HANDLER clause, treat the language as being in the handler
--- 8642,8648 ----
delqry = createPQExpBuffer();
labelq = createPQExpBuffer();
! qlanname = pg_strdup(fmtId(plang->dobj.name));
/*
* If dumping a HANDLER clause, treat the language as being in the handler
*************** convertRegProcReference(const char *proc
*** 9730,9736 ****
char *paren;
bool inquote;
! name = strdup(proc);
/* find non-double-quoted left paren */
inquote = false;
for (paren = name; *paren; paren++)
--- 9731,9737 ----
char *paren;
bool inquote;
! name = pg_strdup(proc);
/* find non-double-quoted left paren */
inquote = false;
for (paren = name; *paren; paren++)
*************** convertOperatorReference(const char *opr
*** 9777,9783 ****
bool inquote;
bool sawdot;
! name = strdup(opr);
/* find non-double-quoted left paren, and check for non-quoted dot */
inquote = false;
sawdot = false;
--- 9778,9784 ----
bool inquote;
bool sawdot;
! name = pg_strdup(opr);
/* find non-double-quoted left paren, and check for non-quoted dot */
inquote = false;
sawdot = false;
*************** convertOperatorReference(const char *opr
*** 9796,9802 ****
/* If not schema-qualified, don't need to add OPERATOR() */
if (!sawdot)
return name;
! oname = malloc(strlen(name) + 11);
sprintf(oname, "OPERATOR(%s)", name);
free(name);
return oname;
--- 9797,9803 ----
/* If not schema-qualified, don't need to add OPERATOR() */
if (!sawdot)
return name;
! oname = pg_malloc(strlen(name) + 11);
sprintf(oname, "OPERATOR(%s)", name);
free(name);
return oname;
*************** convertTSFunction(Oid funcOid)
*** 9843,9849 ****
exit_nicely();
}
! result = strdup(PQgetvalue(res, 0, 0));
PQclear(res);
--- 9844,9850 ----
exit_nicely();
}
! result = pg_strdup(PQgetvalue(res, 0, 0));
PQclear(res);
*************** dumpOpclass(Archive *fout, OpclassInfo *
*** 9969,9979 ****
opckeytype = PQgetvalue(res, 0, i_opckeytype);
opcdefault = PQgetvalue(res, 0, i_opcdefault);
/* opcfamily will still be needed after we PQclear res */
! opcfamily = strdup(PQgetvalue(res, 0, i_opcfamily));
opcfamilyname = PQgetvalue(res, 0, i_opcfamilyname);
opcfamilynsp = PQgetvalue(res, 0, i_opcfamilynsp);
/* amname will still be needed after we PQclear res */
! amname = strdup(PQgetvalue(res, 0, i_amname));
/*
* DROP must be fully qualified in case same name appears in pg_catalog
--- 9970,9980 ----
opckeytype = PQgetvalue(res, 0, i_opckeytype);
opcdefault = PQgetvalue(res, 0, i_opcdefault);
/* opcfamily will still be needed after we PQclear res */
! opcfamily = pg_strdup(PQgetvalue(res, 0, i_opcfamily));
opcfamilyname = PQgetvalue(res, 0, i_opcfamilyname);
opcfamilynsp = PQgetvalue(res, 0, i_opcfamilynsp);
/* amname will still be needed after we PQclear res */
! amname = pg_strdup(PQgetvalue(res, 0, i_amname));
/*
* DROP must be fully qualified in case same name appears in pg_catalog
*************** dumpOpfamily(Archive *fout, OpfamilyInfo
*** 10416,10422 ****
i_amname = PQfnumber(res, "amname");
/* amname will still be needed after we PQclear res */
! amname = strdup(PQgetvalue(res, 0, i_amname));
/*
* DROP must be fully qualified in case same name appears in pg_catalog
--- 10417,10423 ----
i_amname = PQfnumber(res, "amname");
/* amname will still be needed after we PQclear res */
! amname = pg_strdup(PQgetvalue(res, 0, i_amname));
/*
* DROP must be fully qualified in case same name appears in pg_catalog
*************** dumpForeignDataWrapper(Archive *fout, Fd
*** 11436,11442 ****
delq = createPQExpBuffer();
labelq = createPQExpBuffer();
! qfdwname = strdup(fmtId(fdwinfo->dobj.name));
appendPQExpBuffer(q, "CREATE FOREIGN DATA WRAPPER %s",
qfdwname);
--- 11437,11443 ----
delq = createPQExpBuffer();
labelq = createPQExpBuffer();
! qfdwname = pg_strdup(fmtId(fdwinfo->dobj.name));
appendPQExpBuffer(q, "CREATE FOREIGN DATA WRAPPER %s",
qfdwname);
*************** dumpForeignServer(Archive *fout, Foreign
*** 11515,11521 ****
labelq = createPQExpBuffer();
query = createPQExpBuffer();
! qsrvname = strdup(fmtId(srvinfo->dobj.name));
/* look up the foreign-data wrapper */
selectSourceSchema("pg_catalog");
--- 11516,11522 ----
labelq = createPQExpBuffer();
query = createPQExpBuffer();
! qsrvname = pg_strdup(fmtId(srvinfo->dobj.name));
/* look up the foreign-data wrapper */
selectSourceSchema("pg_catalog");
*************** collectSecLabels(Archive *fout, SecLabel
*** 12098,12104 ****
ntups = PQntuples(res);
! labels = (SecLabelItem *) malloc(ntups * sizeof(SecLabelItem));
for (i = 0; i < ntups; i++)
{
--- 12099,12105 ----
ntups = PQntuples(res);
! labels = (SecLabelItem *) pg_malloc(ntups * sizeof(SecLabelItem));
for (i = 0; i < ntups; i++)
{
*************** dumpTable(Archive *fout, TableInfo *tbin
*** 12133,12139 ****
dumpTableSchema(fout, tbinfo);
/* Handle the ACL here */
! namecopy = strdup(fmtId(tbinfo->dobj.name));
dumpACL(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId,
(tbinfo->relkind == RELKIND_SEQUENCE) ? "SEQUENCE" :
"TABLE",
--- 12134,12140 ----
dumpTableSchema(fout, tbinfo);
/* Handle the ACL here */
! namecopy = pg_strdup(fmtId(tbinfo->dobj.name));
dumpACL(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId,
(tbinfo->relkind == RELKIND_SEQUENCE) ? "SEQUENCE" :
"TABLE",
*************** dumpTable(Archive *fout, TableInfo *tbin
*** 12167,12174 ****
char *attnamecopy;
char *acltag;
! attnamecopy = strdup(fmtId(attname));
! acltag = malloc(strlen(tbinfo->dobj.name) + strlen(attname) + 2);
sprintf(acltag, "%s.%s", tbinfo->dobj.name, attname);
/* Column's GRANT type is always TABLE */
dumpACL(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId, "TABLE",
--- 12168,12175 ----
char *attnamecopy;
char *acltag;
! attnamecopy = pg_strdup(fmtId(attname));
! acltag = pg_malloc(strlen(tbinfo->dobj.name) + strlen(attname) + 2);
sprintf(acltag, "%s.%s", tbinfo->dobj.name, attname);
/* Column's GRANT type is always TABLE */
dumpACL(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId, "TABLE",
*************** dumpTableSchema(Archive *fout, TableInfo
*** 12303,12310 ****
check_sql_result(res, g_conn, query->data, PGRES_TUPLES_OK);
i_srvname = PQfnumber(res, "srvname");
i_ftoptions = PQfnumber(res, "ftoptions");
! srvname = strdup(PQgetvalue(res, 0, i_srvname));
! ftoptions = strdup(PQgetvalue(res, 0, i_ftoptions));
PQclear(res);
}
else
--- 12304,12311 ----
check_sql_result(res, g_conn, query->data, PGRES_TUPLES_OK);
i_srvname = PQfnumber(res, "srvname");
i_ftoptions = PQfnumber(res, "ftoptions");
! srvname = pg_strdup(PQgetvalue(res, 0, i_srvname));
! ftoptions = pg_strdup(PQgetvalue(res, 0, i_ftoptions));
PQclear(res);
}
else
*************** getExtensionMembership(ExtensionInfo ext
*** 13975,13981 ****
*/
makeTableDataInfo(configtbl, false);
if (strlen(extconditionarray[j]) > 0)
! configtbl->dataObj->filtercond = strdup(extconditionarray[j]);
}
}
}
--- 13976,13982 ----
*/
makeTableDataInfo(configtbl, false);
if (strlen(extconditionarray[j]) > 0)
! configtbl->dataObj->filtercond = pg_strdup(extconditionarray[j]);
}
}
}
*************** selectSourceSchema(const char *schemaNam
*** 14148,14154 ****
destroyPQExpBuffer(query);
if (curSchemaName)
free(curSchemaName);
! curSchemaName = strdup(schemaName);
}
/*
--- 14149,14155 ----
destroyPQExpBuffer(query);
if (curSchemaName)
free(curSchemaName);
! curSchemaName = pg_strdup(schemaName);
}
/*
*************** getFormattedTypeName(Oid oid, OidOptions
*** 14169,14181 ****
if (oid == 0)
{
if ((opts & zeroAsOpaque) != 0)
! return strdup(g_opaque_type);
else if ((opts & zeroAsAny) != 0)
! return strdup("'any'");
else if ((opts & zeroAsStar) != 0)
! return strdup("*");
else if ((opts & zeroAsNone) != 0)
! return strdup("NONE");
}
query = createPQExpBuffer();
--- 14170,14182 ----
if (oid == 0)
{
if ((opts & zeroAsOpaque) != 0)
! return pg_strdup(g_opaque_type);
else if ((opts & zeroAsAny) != 0)
! return pg_strdup("'any'");
else if ((opts & zeroAsStar) != 0)
! return pg_strdup("*");
else if ((opts & zeroAsNone) != 0)
! return pg_strdup("NONE");
}
query = createPQExpBuffer();
*************** getFormattedTypeName(Oid oid, OidOptions
*** 14214,14225 ****
if (g_fout->remoteVersion >= 70100)
{
/* already quoted */
! result = strdup(PQgetvalue(res, 0, 0));
}
else
{
/* may need to quote it */
! result = strdup(fmtId(PQgetvalue(res, 0, 0)));
}
PQclear(res);
--- 14215,14226 ----
if (g_fout->remoteVersion >= 70100)
{
/* already quoted */
! result = pg_strdup(PQgetvalue(res, 0, 0));
}
else
{
/* may need to quote it */
! result = pg_strdup(fmtId(PQgetvalue(res, 0, 0)));
}
PQclear(res);
*************** myFormatType(const char *typname, int32
*** 14292,14298 ****
if (isarray)
appendPQExpBuffer(buf, "[]");
! result = strdup(buf->data);
destroyPQExpBuffer(buf);
return result;
--- 14293,14299 ----
if (isarray)
appendPQExpBuffer(buf, "[]");
! result = pg_strdup(buf->data);
destroyPQExpBuffer(buf);
return result;
diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h
new file mode 100644
index 3d5d534..c248e75
*** a/src/bin/pg_dump/pg_dump.h
--- b/src/bin/pg_dump/pg_dump.h
*************** extern void simple_string_list_append(Si
*** 521,531 ****
extern bool simple_oid_list_member(SimpleOidList *list, Oid val);
extern bool simple_string_list_member(SimpleStringList *list, const char *val);
- extern char *pg_strdup(const char *string);
- extern void *pg_malloc(size_t size);
- extern void *pg_calloc(size_t nmemb, size_t size);
- extern void *pg_realloc(void *ptr, size_t size);
-
extern void check_conn_and_db(void);
extern void exit_nicely(void);
--- 521,526 ----
diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c
new file mode 100644
index efde0d0..f60ee70
*** a/src/bin/pg_dump/pg_dump_sort.c
--- b/src/bin/pg_dump/pg_dump_sort.c
***************
*** 14,20 ****
*-------------------------------------------------------------------------
*/
#include "pg_backup_archiver.h"
!
static const char *modulename = gettext_noop("sorter");
--- 14,20 ----
*-------------------------------------------------------------------------
*/
#include "pg_backup_archiver.h"
! #include "common.h"
static const char *modulename = gettext_noop("sorter");
*************** sortDumpableObjects(DumpableObject **obj
*** 227,236 ****
if (numObjs <= 0)
return;
! ordering = (DumpableObject **) malloc(numObjs * sizeof(DumpableObject *));
! if (ordering == NULL)
! exit_horribly(NULL, modulename, "out of memory\n");
!
while (!TopoSort(objs, numObjs, ordering, &nOrdering))
findDependencyLoops(ordering, nOrdering, numObjs);
--- 227,233 ----
if (numObjs <= 0)
return;
! ordering = (DumpableObject **) pg_malloc(numObjs * sizeof(DumpableObject *));
while (!TopoSort(objs, numObjs, ordering, &nOrdering))
findDependencyLoops(ordering, nOrdering, numObjs);
*************** TopoSort(DumpableObject **objs,
*** 301,309 ****
return true;
/* Create workspace for the above-described heap */
! pendingHeap = (int *) malloc(numObjs * sizeof(int));
! if (pendingHeap == NULL)
! exit_horribly(NULL, modulename, "out of memory\n");
/*
* Scan the constraints, and for each item in the input, generate a count
--- 298,304 ----
return true;
/* Create workspace for the above-described heap */
! pendingHeap = (int *) pg_malloc(numObjs * sizeof(int));
/*
* Scan the constraints, and for each item in the input, generate a count
*************** TopoSort(DumpableObject **objs,
*** 312,324 ****
* We also make a map showing the input-order index of the item with
* dumpId j.
*/
! beforeConstraints = (int *) malloc((maxDumpId + 1) * sizeof(int));
! if (beforeConstraints == NULL)
! exit_horribly(NULL, modulename, "out of memory\n");
memset(beforeConstraints, 0, (maxDumpId + 1) * sizeof(int));
! idMap = (int *) malloc((maxDumpId + 1) * sizeof(int));
! if (idMap == NULL)
! exit_horribly(NULL, modulename, "out of memory\n");
for (i = 0; i < numObjs; i++)
{
obj = objs[i];
--- 307,315 ----
* We also make a map showing the input-order index of the item with
* dumpId j.
*/
! beforeConstraints = (int *) pg_malloc((maxDumpId + 1) * sizeof(int));
memset(beforeConstraints, 0, (maxDumpId + 1) * sizeof(int));
! idMap = (int *) pg_malloc((maxDumpId + 1) * sizeof(int));
for (i = 0; i < numObjs; i++)
{
obj = objs[i];
*************** findDependencyLoops(DumpableObject **obj
*** 516,524 ****
bool fixedloop;
int i;
! workspace = (DumpableObject **) malloc(totObjs * sizeof(DumpableObject *));
! if (workspace == NULL)
! exit_horribly(NULL, modulename, "out of memory\n");
initiallen = 0;
fixedloop = false;
--- 507,513 ----
bool fixedloop;
int i;
! workspace = (DumpableObject **) pg_malloc(totObjs * sizeof(DumpableObject *));
initiallen = 0;
fixedloop = false;
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
new file mode 100644
index d138da5..4782e68
*** a/src/bin/pg_dump/pg_dumpall.c
--- b/src/bin/pg_dump/pg_dumpall.c
*************** static PGconn *connectDatabase(const cha
*** 60,65 ****
--- 60,68 ----
static PGresult *executeQuery(PGconn *conn, const char *query);
static void executeCommand(PGconn *conn, const char *query);
+ char *pg_strdup(const char *string);
+ void *pg_malloc(size_t size);
+
static char pg_dump_bin[MAXPGPATH];
static PQExpBuffer pgdumpopts;
static bool skip_acls = false;
*************** dumpGroups(PGconn *conn)
*** 916,922 ****
if (strlen(grolist) < 3)
continue;
! grolist = strdup(grolist);
grolist[0] = '(';
grolist[strlen(grolist) - 1] = ')';
printfPQExpBuffer(buf,
--- 919,925 ----
if (strlen(grolist) < 3)
continue;
! grolist = pg_strdup(grolist);
grolist[0] = '(';
grolist[strlen(grolist) - 1] = ')';
printfPQExpBuffer(buf,
*************** dumpTablespaces(PGconn *conn)
*** 1040,1046 ****
char *fspcname;
/* needed for buildACLCommands() */
! fspcname = strdup(fmtId(spcname));
appendPQExpBuffer(buf, "CREATE TABLESPACE %s", fspcname);
appendPQExpBuffer(buf, " OWNER %s", fmtId(spcowner));
--- 1043,1049 ----
char *fspcname;
/* needed for buildACLCommands() */
! fspcname = pg_strdup(fmtId(spcname));
appendPQExpBuffer(buf, "CREATE TABLESPACE %s", fspcname);
appendPQExpBuffer(buf, " OWNER %s", fmtId(spcowner));
*************** dumpCreateDB(PGconn *conn)
*** 1189,1199 ****
if (PQntuples(res) > 0)
{
if (!PQgetisnull(res, 0, 0))
! default_encoding = strdup(PQgetvalue(res, 0, 0));
if (!PQgetisnull(res, 0, 1))
! default_collate = strdup(PQgetvalue(res, 0, 1));
if (!PQgetisnull(res, 0, 2))
! default_ctype = strdup(PQgetvalue(res, 0, 2));
}
PQclear(res);
--- 1192,1202 ----
if (PQntuples(res) > 0)
{
if (!PQgetisnull(res, 0, 0))
! default_encoding = pg_strdup(PQgetvalue(res, 0, 0));
if (!PQgetisnull(res, 0, 1))
! default_collate = pg_strdup(PQgetvalue(res, 0, 1));
if (!PQgetisnull(res, 0, 2))
! default_ctype = pg_strdup(PQgetvalue(res, 0, 2));
}
PQclear(res);
*************** dumpCreateDB(PGconn *conn)
*** 1283,1289 ****
char *dbtablespace = PQgetvalue(res, i, 9);
char *fdbname;
! fdbname = strdup(fmtId(dbname));
resetPQExpBuffer(buf);
--- 1286,1292 ----
char *dbtablespace = PQgetvalue(res, i, 9);
char *fdbname;
! fdbname = pg_strdup(fmtId(dbname));
resetPQExpBuffer(buf);
*************** makeAlterConfigCommand(PGconn *conn, con
*** 1519,1525 ****
char *mine;
PQExpBuffer buf = createPQExpBuffer();
! mine = strdup(arrayitem);
pos = strchr(mine, '=');
if (pos == NULL)
return;
--- 1522,1528 ----
char *mine;
PQExpBuffer buf = createPQExpBuffer();
! mine = pg_strdup(arrayitem);
pos = strchr(mine, '=');
if (pos == NULL)
return;
*************** connectDatabase(const char *dbname, cons
*** 1688,1701 ****
do
{
#define PARAMS_ARRAY_SIZE 7
! const char **keywords = malloc(PARAMS_ARRAY_SIZE * sizeof(*keywords));
! const char **values = malloc(PARAMS_ARRAY_SIZE * sizeof(*values));
!
! if (!keywords || !values)
! {
! fprintf(stderr, _("%s: out of memory\n"), progname);
! exit(1);
! }
keywords[0] = "host";
values[0] = pghost;
--- 1691,1698 ----
do
{
#define PARAMS_ARRAY_SIZE 7
! const char **keywords = pg_malloc(PARAMS_ARRAY_SIZE * sizeof(*keywords));
! const char **values = pg_malloc(PARAMS_ARRAY_SIZE * sizeof(*values));
keywords[0] = "host";
values[0] = pghost;
*************** doShellQuoting(PQExpBuffer buf, const ch
*** 1911,1913 ****
--- 1908,1948 ----
appendPQExpBufferChar(buf, '"');
#endif /* WIN32 */
}
+
+
+ /*
+ * Simpler versions of common.c functions.
+ */
+
+ char *
+ pg_strdup(const char *string)
+ {
+ char *tmp;
+
+ if (!string)
+ {
+ fprintf(stderr, "cannot duplicate null pointer\n");
+ exit(1);
+ }
+ tmp = strdup(string);
+ if (!tmp)
+ {
+ fprintf(stderr, _("%s: out of memory\n"), progname);
+ exit(1);
+ }
+ return tmp;
+ }
+
+ void *
+ pg_malloc(size_t size)
+ {
+ void *tmp;
+
+ tmp = malloc(size);
+ if (!tmp)
+ {
+ fprintf(stderr, _("%s: out of memory\n"), progname);
+ exit(1);
+ }
+ return tmp;
+ }
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
new file mode 100644
index 7731d25..a810ed6
*** a/src/bin/pg_dump/pg_restore.c
--- b/src/bin/pg_dump/pg_restore.c
***************
*** 39,44 ****
--- 39,45 ----
*-------------------------------------------------------------------------
*/
+ #include "common.h"
#include "pg_backup_archiver.h"
#include "dumputils.h"
*************** main(int argc, char **argv)
*** 159,179 ****
opts->createDB = 1;
break;
case 'd':
! opts->dbname = strdup(optarg);
break;
case 'e':
opts->exit_on_error = true;
break;
case 'f': /* output file name */
! opts->filename = strdup(optarg);
break;
case 'F':
if (strlen(optarg) != 0)
! opts->formatName = strdup(optarg);
break;
case 'h':
if (strlen(optarg) != 0)
! opts->pghost = strdup(optarg);
break;
case 'i':
/* ignored, deprecated option */
--- 160,180 ----
opts->createDB = 1;
break;
case 'd':
! opts->dbname = pg_strdup(optarg);
break;
case 'e':
opts->exit_on_error = true;
break;
case 'f': /* output file name */
! opts->filename = pg_strdup(optarg);
break;
case 'F':
if (strlen(optarg) != 0)
! opts->formatName = pg_strdup(optarg);
break;
case 'h':
if (strlen(optarg) != 0)
! opts->pghost = pg_strdup(optarg);
break;
case 'i':
/* ignored, deprecated option */
*************** main(int argc, char **argv)
*** 188,198 ****
break;
case 'L': /* input TOC summary file name */
! opts->tocFile = strdup(optarg);
break;
case 'n': /* Dump data for this schema only */
! opts->schemaNames = strdup(optarg);
break;
case 'O':
--- 189,199 ----
break;
case 'L': /* input TOC summary file name */
! opts->tocFile = pg_strdup(optarg);
break;
case 'n': /* Dump data for this schema only */
! opts->schemaNames = pg_strdup(optarg);
break;
case 'O':
*************** main(int argc, char **argv)
*** 201,207 ****
case 'p':
if (strlen(optarg) != 0)
! opts->pgport = strdup(optarg);
break;
case 'R':
/* no-op, still accepted for backwards compatibility */
--- 202,208 ----
case 'p':
if (strlen(optarg) != 0)
! opts->pgport = pg_strdup(optarg);
break;
case 'R':
/* no-op, still accepted for backwards compatibility */
*************** main(int argc, char **argv)
*** 209,237 ****
case 'P': /* Function */
opts->selTypes = 1;
opts->selFunction = 1;
! opts->functionNames = strdup(optarg);
break;
case 'I': /* Index */
opts->selTypes = 1;
opts->selIndex = 1;
! opts->indexNames = strdup(optarg);
break;
case 'T': /* Trigger */
opts->selTypes = 1;
opts->selTrigger = 1;
! opts->triggerNames = strdup(optarg);
break;
case 's': /* dump schema only */
opts->schemaOnly = 1;
break;
case 'S': /* Superuser username */
if (strlen(optarg) != 0)
! opts->superuser = strdup(optarg);
break;
case 't': /* Dump data for this table only */
opts->selTypes = 1;
opts->selTable = 1;
! opts->tableNames = strdup(optarg);
break;
case 'U':
--- 210,238 ----
case 'P': /* Function */
opts->selTypes = 1;
opts->selFunction = 1;
! opts->functionNames = pg_strdup(optarg);
break;
case 'I': /* Index */
opts->selTypes = 1;
opts->selIndex = 1;
! opts->indexNames = pg_strdup(optarg);
break;
case 'T': /* Trigger */
opts->selTypes = 1;
opts->selTrigger = 1;
! opts->triggerNames = pg_strdup(optarg);
break;
case 's': /* dump schema only */
opts->schemaOnly = 1;
break;
case 'S': /* Superuser username */
if (strlen(optarg) != 0)
! opts->superuser = pg_strdup(optarg);
break;
case 't': /* Dump data for this table only */
opts->selTypes = 1;
opts->selTable = 1;
! opts->tableNames = pg_strdup(optarg);
break;
case 'U':
Bruce Momjian wrote:
I developed the attached patch to handle this. I moved the catalog code
from common.c into dumpcatalog.c, so there are just memory routines now
in common.c. I created new memory routines in pg_dumpall.c because
there is no AH structure in pg_dumpall.c. I then modified all the calls
to use the new routines, and removed the NULL return checks that were no
longer necessary.
Applied.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +