aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meskes <meskes@postgresql.org>2010-08-17 09:41:49 +0000
committerMichael Meskes <meskes@postgresql.org>2010-08-17 09:41:49 +0000
commitb9b65b7417595286fc6932bfe1144ebcf7d0e3bc (patch)
tree176398031c1e9abdc2fa9bdeabfeda26c7fa25c7
parent0b77050e842f0eccb80210e76d40bd05b6bbb38a (diff)
downloadpostgresql-b9b65b7417595286fc6932bfe1144ebcf7d0e3bc.tar.gz
postgresql-b9b65b7417595286fc6932bfe1144ebcf7d0e3bc.zip
Applied Zoltan's patch to fix a few memleaks in ecpg's pgtypeslib.
-rw-r--r--src/interfaces/ecpg/pgtypeslib/numeric.c9
-rw-r--r--src/interfaces/ecpg/test/compat_informix/dec_test.pgc4
-rw-r--r--src/interfaces/ecpg/test/expected/compat_informix-dec_test.c4
-rw-r--r--src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c9
-rw-r--r--src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr2
-rw-r--r--src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.c2
-rw-r--r--src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c11
-rw-r--r--src/interfaces/ecpg/test/expected/pgtypeslib-num_test.stderr2
-rw-r--r--src/interfaces/ecpg/test/expected/pgtypeslib-num_test2.c7
-rw-r--r--src/interfaces/ecpg/test/expected/sql-array.c2
-rw-r--r--src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc1
-rw-r--r--src/interfaces/ecpg/test/pgtypeslib/dt_test2.pgc2
-rw-r--r--src/interfaces/ecpg/test/pgtypeslib/num_test.pgc3
-rw-r--r--src/interfaces/ecpg/test/pgtypeslib/num_test2.pgc7
-rw-r--r--src/interfaces/ecpg/test/sql/array.pgc2
15 files changed, 54 insertions, 13 deletions
diff --git a/src/interfaces/ecpg/pgtypeslib/numeric.c b/src/interfaces/ecpg/pgtypeslib/numeric.c
index 93505eaab18..c379811b8f9 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.33 2006/10/04 00:30:12 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/numeric.c,v 1.33.6.1 2010/08/17 09:41:48 meskes Exp $ */
#include "postgres_fe.h"
#include <ctype.h>
@@ -389,7 +389,7 @@ PGTYPESnumeric_from_asc(char *str, char **endptr)
ret = set_var_from_str(str, ptr, value);
if (ret)
{
- free(value);
+ PGTYPESnumeric_free(value);
return (NULL);
}
@@ -1576,8 +1576,12 @@ PGTYPESnumeric_to_long(numeric *nv, long *lp)
errno = 0;
*lp = strtol(s, &endptr, 10);
if (endptr == s)
+ {
/* this should not happen actually */
+ free(s);
return -1;
+ }
+ free(s);
if (errno == ERANGE)
{
if (*lp == LONG_MIN)
@@ -1586,7 +1590,6 @@ PGTYPESnumeric_to_long(numeric *nv, long *lp)
errno = PGTYPES_NUM_OVERFLOW;
return -1;
}
- free(s);
return 0;
}
diff --git a/src/interfaces/ecpg/test/compat_informix/dec_test.pgc b/src/interfaces/ecpg/test/compat_informix/dec_test.pgc
index d1a01b556dd..b374bda724f 100644
--- a/src/interfaces/ecpg/test/compat_informix/dec_test.pgc
+++ b/src/interfaces/ecpg/test/compat_informix/dec_test.pgc
@@ -60,6 +60,7 @@ main(void)
{
check_errno();
printf("dec[%d,0]: r: %d\n", i, r);
+ PGTYPESdecimal_free(dec);
continue;
}
decarr = realloc(decarr, sizeof(decimal *) * (count + 1));
@@ -200,7 +201,10 @@ main(void)
{
dectoasc(decarr[i], buf, BUFSIZE-1, -1);
printf("%d: %s\n", i, buf);
+
+ PGTYPESdecimal_free(decarr[i]);
}
+ free(decarr);
return (0);
}
diff --git a/src/interfaces/ecpg/test/expected/compat_informix-dec_test.c b/src/interfaces/ecpg/test/expected/compat_informix-dec_test.c
index 9bd05bc9e9e..3b443e3ffdc 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-dec_test.c
+++ b/src/interfaces/ecpg/test/expected/compat_informix-dec_test.c
@@ -80,6 +80,7 @@ main(void)
{
check_errno();
printf("dec[%d,0]: r: %d\n", i, r);
+ PGTYPESdecimal_free(dec);
continue;
}
decarr = realloc(decarr, sizeof(decimal *) * (count + 1));
@@ -220,7 +221,10 @@ main(void)
{
dectoasc(decarr[i], buf, BUFSIZE-1, -1);
printf("%d: %s\n", i, buf);
+
+ PGTYPESdecimal_free(decarr[i]);
}
+ free(decarr);
return (0);
}
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
index a52ad13fb9a..b0b3239b9fd 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
@@ -123,6 +123,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
PGTYPESinterval_copy(iv1, &iv2);
text = PGTYPESinterval_to_asc(&iv2);
printf ("interval: %s\n", text);
+ PGTYPESinterval_free(iv1);
free(text);
PGTYPESdate_mdyjul(mdy, &date2);
@@ -430,16 +431,16 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
free(text);
{ ECPGtrans(__LINE__, NULL, "rollback");
-#line 358 "dt_test.pgc"
+#line 359 "dt_test.pgc"
if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 358 "dt_test.pgc"
+#line 359 "dt_test.pgc"
{ ECPGdisconnect(__LINE__, "CURRENT");
-#line 359 "dt_test.pgc"
+#line 360 "dt_test.pgc"
if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 359 "dt_test.pgc"
+#line 360 "dt_test.pgc"
return (0);
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr
index 08680b9ccf3..c0033c52cc5 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr
@@ -42,7 +42,7 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 38: RESULT: 2000-07-12 17:34:29 offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGtrans on line 358: action "rollback"; connection "regress1"
+[NO_PID]: ECPGtrans on line 359: action "rollback"; connection "regress1"
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: connection regress1 closed
[NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.c b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.c
index cd083f5d2e3..2497eb1a235 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.c
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.c
@@ -139,6 +139,7 @@ main(void)
printf("TS[%d,%d]: %s\n",
i, j, errno ? "-" : text);
free(text);
+ free(t);
}
}
}
@@ -169,6 +170,7 @@ main(void)
printf("interval_copy[%d]: %s\n", i, text ? text : "-");
free(text);
PGTYPESinterval_free(ic);
+ PGTYPESinterval_free(i1);
}
return (0);
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c b/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c
index 09554a340a4..6c6eb0b23a6 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c
@@ -131,6 +131,9 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
PGTYPESnumeric_to_double(res, &d);
printf("div = %s %e\n", text, d);
+ PGTYPESnumeric_free(value1);
+ PGTYPESnumeric_free(value2);
+
value1 = PGTYPESnumeric_from_asc("2E7", NULL);
value2 = PGTYPESnumeric_from_asc("14", NULL);
i = PGTYPESnumeric_to_long(value1, &l1) | PGTYPESnumeric_to_long(value2, &l2);
@@ -142,16 +145,16 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
PGTYPESnumeric_free(res);
{ ECPGtrans(__LINE__, NULL, "rollback");
-#line 90 "num_test.pgc"
+#line 93 "num_test.pgc"
if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 90 "num_test.pgc"
+#line 93 "num_test.pgc"
{ ECPGdisconnect(__LINE__, "CURRENT");
-#line 91 "num_test.pgc"
+#line 94 "num_test.pgc"
if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 91 "num_test.pgc"
+#line 94 "num_test.pgc"
return (0);
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.stderr b/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.stderr
index eaeed3d5306..bd89aec9f29 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.stderr
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.stderr
@@ -26,7 +26,7 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 66: RESULT: 2369.7000000 offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGtrans on line 90: action "rollback"; connection "regress1"
+[NO_PID]: ECPGtrans on line 93: action "rollback"; connection "regress1"
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: connection regress1 closed
[NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-num_test2.c b/src/interfaces/ecpg/test/expected/pgtypeslib-num_test2.c
index 4f15226d255..83636ad8800 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-num_test2.c
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-num_test2.c
@@ -211,6 +211,11 @@ main(void)
printf("num[d,%d,%d]: %s\n", i, j, text);
free(text);
}
+
+ PGTYPESnumeric_free(a);
+ PGTYPESnumeric_free(s);
+ PGTYPESnumeric_free(m);
+ PGTYPESnumeric_free(d);
}
}
@@ -219,7 +224,9 @@ main(void)
text = PGTYPESnumeric_to_asc(numarr[i], -1);
printf("%d: %s\n", i, text);
free(text);
+ PGTYPESnumeric_free(numarr[i]);
}
+ free(numarr);
return (0);
}
diff --git a/src/interfaces/ecpg/test/expected/sql-array.c b/src/interfaces/ecpg/test/expected/sql-array.c
index ade0ccb9379..cdd2bea0789 100644
--- a/src/interfaces/ecpg/test/expected/sql-array.c
+++ b/src/interfaces/ecpg/test/expected/sql-array.c
@@ -273,5 +273,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
#line 74 "array.pgc"
+ free(t);
+
return (0);
}
diff --git a/src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc b/src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc
index 3ed20614541..4e3c4404437 100644
--- a/src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc
+++ b/src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc
@@ -49,6 +49,7 @@ main(void)
PGTYPESinterval_copy(iv1, &iv2);
text = PGTYPESinterval_to_asc(&iv2);
printf ("interval: %s\n", text);
+ PGTYPESinterval_free(iv1);
free(text);
PGTYPESdate_mdyjul(mdy, &date2);
diff --git a/src/interfaces/ecpg/test/pgtypeslib/dt_test2.pgc b/src/interfaces/ecpg/test/pgtypeslib/dt_test2.pgc
index 27d616751d9..5ab2dfeccf7 100644
--- a/src/interfaces/ecpg/test/pgtypeslib/dt_test2.pgc
+++ b/src/interfaces/ecpg/test/pgtypeslib/dt_test2.pgc
@@ -104,6 +104,7 @@ main(void)
printf("TS[%d,%d]: %s\n",
i, j, errno ? "-" : text);
free(text);
+ free(t);
}
}
}
@@ -134,6 +135,7 @@ main(void)
printf("interval_copy[%d]: %s\n", i, text ? text : "-");
free(text);
PGTYPESinterval_free(ic);
+ PGTYPESinterval_free(i1);
}
return (0);
diff --git a/src/interfaces/ecpg/test/pgtypeslib/num_test.pgc b/src/interfaces/ecpg/test/pgtypeslib/num_test.pgc
index 3d62e694b7a..fcdc3964356 100644
--- a/src/interfaces/ecpg/test/pgtypeslib/num_test.pgc
+++ b/src/interfaces/ecpg/test/pgtypeslib/num_test.pgc
@@ -77,6 +77,9 @@ main(void)
PGTYPESnumeric_to_double(res, &d);
printf("div = %s %e\n", text, d);
+ PGTYPESnumeric_free(value1);
+ PGTYPESnumeric_free(value2);
+
value1 = PGTYPESnumeric_from_asc("2E7", NULL);
value2 = PGTYPESnumeric_from_asc("14", NULL);
i = PGTYPESnumeric_to_long(value1, &l1) | PGTYPESnumeric_to_long(value2, &l2);
diff --git a/src/interfaces/ecpg/test/pgtypeslib/num_test2.pgc b/src/interfaces/ecpg/test/pgtypeslib/num_test2.pgc
index 0b2a2e654ca..2ac666f7c02 100644
--- a/src/interfaces/ecpg/test/pgtypeslib/num_test2.pgc
+++ b/src/interfaces/ecpg/test/pgtypeslib/num_test2.pgc
@@ -193,6 +193,11 @@ main(void)
printf("num[d,%d,%d]: %s\n", i, j, text);
free(text);
}
+
+ PGTYPESnumeric_free(a);
+ PGTYPESnumeric_free(s);
+ PGTYPESnumeric_free(m);
+ PGTYPESnumeric_free(d);
}
}
@@ -201,7 +206,9 @@ main(void)
text = PGTYPESnumeric_to_asc(numarr[i], -1);
printf("%d: %s\n", i, text);
free(text);
+ PGTYPESnumeric_free(numarr[i]);
}
+ free(numarr);
return (0);
}
diff --git a/src/interfaces/ecpg/test/sql/array.pgc b/src/interfaces/ecpg/test/sql/array.pgc
index d589a242f57..d74a1354e5f 100644
--- a/src/interfaces/ecpg/test/sql/array.pgc
+++ b/src/interfaces/ecpg/test/sql/array.pgc
@@ -73,5 +73,7 @@ EXEC SQL END DECLARE SECTION;
EXEC SQL DISCONNECT;
+ free(t);
+
return (0);
}