From 524d65d459781c77e8d707a04a24360a05b6ab77 Mon Sep 17 00:00:00 2001
From: Michael Meskes <meskes@postgresql.org>
Date: Mon, 24 Apr 2006 09:45:22 +0000
Subject: [PATCH] Fixed memory leak bugs found by Martijn Oosterhout.

---
 src/interfaces/ecpg/ChangeLog            |  4 ++++
 src/interfaces/ecpg/compatlib/informix.c | 10 +++++-----
 src/interfaces/ecpg/ecpglib/execute.c    |  4 ++--
 src/interfaces/ecpg/pgtypeslib/numeric.c | 15 +++++----------
 4 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/src/interfaces/ecpg/ChangeLog b/src/interfaces/ecpg/ChangeLog
index 2042647ef82..60a77fa6bc7 100644
--- a/src/interfaces/ecpg/ChangeLog
+++ b/src/interfaces/ecpg/ChangeLog
@@ -1997,6 +1997,10 @@ Tu Feb  7 18:48:14 CET 2006
 Fri, 17 Mar 2006 16:38:19 +0100
 
 	- Fixed bug 2330: Wrong error code in case of a duplicate key
+
+Mo Apr 24 11:40:05 CEST 2006
+
+	- Fixed memory leak bugs found by Martijn Oosterhout.
 	- Set ecpg library version to 5.2.
 	- Set ecpg version to 4.2.1.
 
diff --git a/src/interfaces/ecpg/compatlib/informix.c b/src/interfaces/ecpg/compatlib/informix.c
index 4604c6e797d..84c2574e15c 100644
--- a/src/interfaces/ecpg/compatlib/informix.c
+++ b/src/interfaces/ecpg/compatlib/informix.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.41 2006/03/11 04:38:39 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.42 2006/04/24 09:45:22 meskes Exp $ */
 
 #include <stdlib.h>
 #include <string.h>
@@ -166,15 +166,15 @@ ecpg_strndup(const char *str, size_t len)
 int
 deccvasc(char *cp, int len, decimal *np)
 {
-	char	   *str = ecpg_strndup(cp, len);	/* decimal_in always converts
-												 * the complete string */
-	int			ret = 0;
-	numeric    *result;
+	char		*str;
+	int		ret = 0;
+	numeric		*result;
 
 	rsetnull(CDECIMALTYPE, (char *) np);
 	if (risnull(CSTRINGTYPE, cp))
 		return 0;
 
+	str = ecpg_strndup(cp, len);	/* decimal_in always converts the complete string */
 	if (!str)
 		ret = ECPG_INFORMIX_NUM_UNDERFLOW;
 	else
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index 491d6e6040b..2cca58aa098 100644
--- a/src/interfaces/ecpg/ecpglib/execute.c
+++ b/src/interfaces/ecpg/ecpglib/execute.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.44 2005/11/30 12:49:49 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.45 2006/04/24 09:45:22 meskes Exp $ */
 
 /*
  * The aim is to get a simpler inteface to the database routines.
@@ -860,7 +860,7 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 
 					if (var->arrsize > 1)
 					{
-						for (element = 0; element < var->arrsize; element++)
+						for (element = 0; element < var->arrsize; element++, nval = PGTYPESnumeric_new())
 						{
 							if (var->type == ECPGt_numeric)
 								PGTYPESnumeric_copy((numeric *) ((var + var->offset * element)->value), nval);
diff --git a/src/interfaces/ecpg/pgtypeslib/numeric.c b/src/interfaces/ecpg/pgtypeslib/numeric.c
index c35fe9e3a18..4f1ab17fac1 100644
--- a/src/interfaces/ecpg/pgtypeslib/numeric.c
+++ b/src/interfaces/ecpg/pgtypeslib/numeric.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/numeric.c,v 1.25 2006/03/11 04:38:40 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/numeric.c,v 1.26 2006/04/24 09:45:22 meskes Exp $ */
 
 #include "postgres_fe.h"
 #include <ctype.h>
@@ -364,24 +364,19 @@ PGTYPESnumeric_from_asc(char *str, char **endptr)
 	numeric    *value = (numeric *) pgtypes_alloc(sizeof(numeric));
 	int			ret;
 
-#if 0
-	long		typmod = -1;
-#endif
 	char	   *realptr;
 	char	  **ptr = (endptr != NULL) ? endptr : &realptr;
 
-	if (!value)
+	if (!value)	
 		return (NULL);
 
 	ret = set_var_from_str(str, ptr, value);
 	if (ret)
+	{
+		free(value);
 		return (NULL);
+	}
 
-#if 0
-	ret = apply_typmod(value, typmod);
-	if (ret)
-		return (NULL);
-#endif
 	return (value);
 }
 
-- 
GitLab