From 228697179adac8da31e0a832e730d0927cf6d0c1 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Sat, 3 May 2003 22:18:59 +0000
Subject: [PATCH] Fix erroneous space calculation leading to core dump in
 dumpProcLangs, per report from Olivier Prenant.  Also fix off-by-one space
 calculation in ReadToc; this woould not have hurt us until we had more than
 100 dependencies for a single object, but wrong is wrong.

---
 src/bin/pg_dump/pg_backup_archiver.c | 7 +++++--
 src/bin/pg_dump/pg_dump.c            | 4 ++--
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 1ef3f371f4a..df8e09c3d28 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *		$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.70 2003/03/10 22:28:19 tgl Exp $
+ *		$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.71 2003/05/03 22:18:59 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1916,7 +1916,7 @@ ReadToc(ArchiveHandle *AH)
 			depIdx = 0;
 			do
 			{
-				if (depIdx > depSize)
+				if (depIdx >= depSize)
 				{
 					depSize *= 2;
 					deps = realloc(deps, sizeof(char *) * depSize);
@@ -1932,7 +1932,10 @@ ReadToc(ArchiveHandle *AH)
 			if (depIdx > 1)		/* We have a non-null entry */
 				te->depOid = realloc(deps, sizeof(char *) * depIdx);	/* trim it */
 			else
+			{
+				free(deps);
 				te->depOid = NULL;		/* no deps */
+			}
 		}
 		else
 			te->depOid = NULL;
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 84cf3950ec1..6de655b6cd1 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -12,7 +12,7 @@
  *	by PostgreSQL
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.327 2003/04/25 02:28:22 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.328 2003/05/03 22:18:59 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -3591,7 +3591,7 @@ dumpProcLangs(Archive *fout, FuncInfo finfo[], int numFuncs)
 		resetPQExpBuffer(delqry);
 
 		/* Make a dependency to ensure function is dumped first */
-		deps = malloc(sizeof(char *) * (2 + (strcmp(lanvalidator, "0") != 0) ? 1 : 0));
+		deps = malloc(sizeof(char *) * 10);
 		depIdx = 0;
 
 		(*deps)[depIdx++] = strdup(lanplcallfoid);
-- 
GitLab