Commit 9a8d15bd authored by Michael Meskes's avatar Michael Meskes

Applied Zoltan's patch to fix a few memleaks in ecpg's pgtypeslib.

parent 7b243aa6
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/numeric.c,v 1.35 2010/02/02 16:09:12 meskes Exp $ */ /* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/numeric.c,v 1.36 2010/08/17 09:36:04 meskes Exp $ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include <ctype.h> #include <ctype.h>
...@@ -417,7 +417,7 @@ PGTYPESnumeric_from_asc(char *str, char **endptr) ...@@ -417,7 +417,7 @@ PGTYPESnumeric_from_asc(char *str, char **endptr)
ret = set_var_from_str(str, ptr, value); ret = set_var_from_str(str, ptr, value);
if (ret) if (ret)
{ {
free(value); PGTYPESnumeric_free(value);
return (NULL); return (NULL);
} }
...@@ -1602,8 +1602,12 @@ PGTYPESnumeric_to_long(numeric *nv, long *lp) ...@@ -1602,8 +1602,12 @@ PGTYPESnumeric_to_long(numeric *nv, long *lp)
errno = 0; errno = 0;
*lp = strtol(s, &endptr, 10); *lp = strtol(s, &endptr, 10);
if (endptr == s) if (endptr == s)
{
/* this should not happen actually */ /* this should not happen actually */
free(s);
return -1; return -1;
}
free(s);
if (errno == ERANGE) if (errno == ERANGE)
{ {
if (*lp == LONG_MIN) if (*lp == LONG_MIN)
...@@ -1612,7 +1616,6 @@ PGTYPESnumeric_to_long(numeric *nv, long *lp) ...@@ -1612,7 +1616,6 @@ PGTYPESnumeric_to_long(numeric *nv, long *lp)
errno = PGTYPES_NUM_OVERFLOW; errno = PGTYPES_NUM_OVERFLOW;
return -1; return -1;
} }
free(s);
return 0; return 0;
} }
......
...@@ -60,6 +60,7 @@ main(void) ...@@ -60,6 +60,7 @@ main(void)
{ {
check_errno(); check_errno();
printf("dec[%d,0]: r: %d\n", i, r); printf("dec[%d,0]: r: %d\n", i, r);
PGTYPESdecimal_free(dec);
continue; continue;
} }
decarr = realloc(decarr, sizeof(decimal *) * (count + 1)); decarr = realloc(decarr, sizeof(decimal *) * (count + 1));
...@@ -200,7 +201,10 @@ main(void) ...@@ -200,7 +201,10 @@ main(void)
{ {
dectoasc(decarr[i], buf, BUFSIZE-1, -1); dectoasc(decarr[i], buf, BUFSIZE-1, -1);
printf("%d: %s\n", i, buf); printf("%d: %s\n", i, buf);
PGTYPESdecimal_free(decarr[i]);
} }
free(decarr);
return (0); return (0);
} }
......
...@@ -80,6 +80,7 @@ main(void) ...@@ -80,6 +80,7 @@ main(void)
{ {
check_errno(); check_errno();
printf("dec[%d,0]: r: %d\n", i, r); printf("dec[%d,0]: r: %d\n", i, r);
PGTYPESdecimal_free(dec);
continue; continue;
} }
decarr = realloc(decarr, sizeof(decimal *) * (count + 1)); decarr = realloc(decarr, sizeof(decimal *) * (count + 1));
...@@ -220,7 +221,10 @@ main(void) ...@@ -220,7 +221,10 @@ main(void)
{ {
dectoasc(decarr[i], buf, BUFSIZE-1, -1); dectoasc(decarr[i], buf, BUFSIZE-1, -1);
printf("%d: %s\n", i, buf); printf("%d: %s\n", i, buf);
PGTYPESdecimal_free(decarr[i]);
} }
free(decarr);
return (0); return (0);
} }
......
...@@ -123,6 +123,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );} ...@@ -123,6 +123,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
PGTYPESinterval_copy(iv1, &iv2); PGTYPESinterval_copy(iv1, &iv2);
text = PGTYPESinterval_to_asc(&iv2); text = PGTYPESinterval_to_asc(&iv2);
printf ("interval: %s\n", text); printf ("interval: %s\n", text);
PGTYPESinterval_free(iv1);
free(text); free(text);
PGTYPESdate_mdyjul(mdy, &date2); PGTYPESdate_mdyjul(mdy, &date2);
...@@ -430,16 +431,16 @@ if (sqlca.sqlcode < 0) sqlprint ( );} ...@@ -430,16 +431,16 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
free(text); free(text);
{ ECPGtrans(__LINE__, NULL, "rollback"); { ECPGtrans(__LINE__, NULL, "rollback");
#line 358 "dt_test.pgc" #line 359 "dt_test.pgc"
if (sqlca.sqlcode < 0) sqlprint ( );} if (sqlca.sqlcode < 0) sqlprint ( );}
#line 358 "dt_test.pgc" #line 359 "dt_test.pgc"
{ ECPGdisconnect(__LINE__, "CURRENT"); { ECPGdisconnect(__LINE__, "CURRENT");
#line 359 "dt_test.pgc" #line 360 "dt_test.pgc"
if (sqlca.sqlcode < 0) sqlprint ( );} if (sqlca.sqlcode < 0) sqlprint ( );}
#line 359 "dt_test.pgc" #line 360 "dt_test.pgc"
return (0); return (0);
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
[NO_PID]: sqlca: code: 0, state: 00000 [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: no [NO_PID]: ecpg_get_data on line 38: RESULT: 2000-07-12 17:34:29 offset: -1; array: no
[NO_PID]: sqlca: code: 0, state: 00000 [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]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: connection regress1 closed [NO_PID]: ecpg_finish: connection regress1 closed
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
...@@ -139,6 +139,7 @@ main(void) ...@@ -139,6 +139,7 @@ main(void)
printf("TS[%d,%d]: %s\n", printf("TS[%d,%d]: %s\n",
i, j, errno ? "-" : text); i, j, errno ? "-" : text);
free(text); free(text);
free(t);
} }
} }
} }
...@@ -169,6 +170,7 @@ main(void) ...@@ -169,6 +170,7 @@ main(void)
printf("interval_copy[%d]: %s\n", i, text ? text : "-"); printf("interval_copy[%d]: %s\n", i, text ? text : "-");
free(text); free(text);
PGTYPESinterval_free(ic); PGTYPESinterval_free(ic);
PGTYPESinterval_free(i1);
} }
return (0); return (0);
......
...@@ -252,17 +252,19 @@ if (sqlca.sqlcode < 0) sqlprint ( );} ...@@ -252,17 +252,19 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
#line 84 "nan_test.pgc" #line 84 "nan_test.pgc"
PGTYPESnumeric_free(num);
{ ECPGtrans(__LINE__, NULL, "rollback"); { ECPGtrans(__LINE__, NULL, "rollback");
#line 86 "nan_test.pgc" #line 88 "nan_test.pgc"
if (sqlca.sqlcode < 0) sqlprint ( );} if (sqlca.sqlcode < 0) sqlprint ( );}
#line 86 "nan_test.pgc" #line 88 "nan_test.pgc"
{ ECPGdisconnect(__LINE__, "CURRENT"); { ECPGdisconnect(__LINE__, "CURRENT");
#line 87 "nan_test.pgc" #line 89 "nan_test.pgc"
if (sqlca.sqlcode < 0) sqlprint ( );} if (sqlca.sqlcode < 0) sqlprint ( );}
#line 87 "nan_test.pgc" #line 89 "nan_test.pgc"
return (0); return (0);
......
...@@ -354,7 +354,7 @@ ...@@ -354,7 +354,7 @@
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 84: OK: CLOSE CURSOR [NO_PID]: ecpg_execute on line 84: OK: CLOSE CURSOR
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGtrans on line 86: action "rollback"; connection "regress1" [NO_PID]: ECPGtrans on line 88: action "rollback"; connection "regress1"
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: connection regress1 closed [NO_PID]: ecpg_finish: connection regress1 closed
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
...@@ -131,6 +131,9 @@ if (sqlca.sqlcode < 0) sqlprint ( );} ...@@ -131,6 +131,9 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
PGTYPESnumeric_to_double(res, &d); PGTYPESnumeric_to_double(res, &d);
printf("div = %s %e\n", text, d); printf("div = %s %e\n", text, d);
PGTYPESnumeric_free(value1);
PGTYPESnumeric_free(value2);
value1 = PGTYPESnumeric_from_asc("2E7", NULL); value1 = PGTYPESnumeric_from_asc("2E7", NULL);
value2 = PGTYPESnumeric_from_asc("14", NULL); value2 = PGTYPESnumeric_from_asc("14", NULL);
i = PGTYPESnumeric_to_long(value1, &l1) | PGTYPESnumeric_to_long(value2, &l2); i = PGTYPESnumeric_to_long(value1, &l1) | PGTYPESnumeric_to_long(value2, &l2);
...@@ -142,16 +145,16 @@ if (sqlca.sqlcode < 0) sqlprint ( );} ...@@ -142,16 +145,16 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
PGTYPESnumeric_free(res); PGTYPESnumeric_free(res);
{ ECPGtrans(__LINE__, NULL, "rollback"); { ECPGtrans(__LINE__, NULL, "rollback");
#line 90 "num_test.pgc" #line 93 "num_test.pgc"
if (sqlca.sqlcode < 0) sqlprint ( );} if (sqlca.sqlcode < 0) sqlprint ( );}
#line 90 "num_test.pgc" #line 93 "num_test.pgc"
{ ECPGdisconnect(__LINE__, "CURRENT"); { ECPGdisconnect(__LINE__, "CURRENT");
#line 91 "num_test.pgc" #line 94 "num_test.pgc"
if (sqlca.sqlcode < 0) sqlprint ( );} if (sqlca.sqlcode < 0) sqlprint ( );}
#line 91 "num_test.pgc" #line 94 "num_test.pgc"
return (0); return (0);
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 66: RESULT: 2369.7000000 offset: -1; array: no [NO_PID]: ecpg_get_data on line 66: RESULT: 2369.7000000 offset: -1; array: no
[NO_PID]: sqlca: code: 0, state: 00000 [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]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: connection regress1 closed [NO_PID]: ecpg_finish: connection regress1 closed
[NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: sqlca: code: 0, state: 00000
...@@ -211,6 +211,11 @@ main(void) ...@@ -211,6 +211,11 @@ main(void)
printf("num[d,%d,%d]: %s\n", i, j, text); printf("num[d,%d,%d]: %s\n", i, j, text);
free(text); free(text);
} }
PGTYPESnumeric_free(a);
PGTYPESnumeric_free(s);
PGTYPESnumeric_free(m);
PGTYPESnumeric_free(d);
} }
} }
...@@ -219,7 +224,9 @@ main(void) ...@@ -219,7 +224,9 @@ main(void)
text = PGTYPESnumeric_to_asc(numarr[i], -1); text = PGTYPESnumeric_to_asc(numarr[i], -1);
printf("%d: %s\n", i, text); printf("%d: %s\n", i, text);
free(text); free(text);
PGTYPESnumeric_free(numarr[i]);
} }
free(numarr);
return (0); return (0);
} }
......
...@@ -273,5 +273,7 @@ if (sqlca.sqlcode < 0) sqlprint();} ...@@ -273,5 +273,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
#line 74 "array.pgc" #line 74 "array.pgc"
free(t);
return (0); return (0);
} }
...@@ -49,6 +49,7 @@ main(void) ...@@ -49,6 +49,7 @@ main(void)
PGTYPESinterval_copy(iv1, &iv2); PGTYPESinterval_copy(iv1, &iv2);
text = PGTYPESinterval_to_asc(&iv2); text = PGTYPESinterval_to_asc(&iv2);
printf ("interval: %s\n", text); printf ("interval: %s\n", text);
PGTYPESinterval_free(iv1);
free(text); free(text);
PGTYPESdate_mdyjul(mdy, &date2); PGTYPESdate_mdyjul(mdy, &date2);
......
...@@ -104,6 +104,7 @@ main(void) ...@@ -104,6 +104,7 @@ main(void)
printf("TS[%d,%d]: %s\n", printf("TS[%d,%d]: %s\n",
i, j, errno ? "-" : text); i, j, errno ? "-" : text);
free(text); free(text);
free(t);
} }
} }
} }
...@@ -134,6 +135,7 @@ main(void) ...@@ -134,6 +135,7 @@ main(void)
printf("interval_copy[%d]: %s\n", i, text ? text : "-"); printf("interval_copy[%d]: %s\n", i, text ? text : "-");
free(text); free(text);
PGTYPESinterval_free(ic); PGTYPESinterval_free(ic);
PGTYPESinterval_free(i1);
} }
return (0); return (0);
......
...@@ -83,6 +83,8 @@ main(void) ...@@ -83,6 +83,8 @@ main(void)
} }
exec sql close cur1; exec sql close cur1;
PGTYPESnumeric_free(num);
exec sql rollback; exec sql rollback;
exec sql disconnect; exec sql disconnect;
......
...@@ -77,6 +77,9 @@ main(void) ...@@ -77,6 +77,9 @@ main(void)
PGTYPESnumeric_to_double(res, &d); PGTYPESnumeric_to_double(res, &d);
printf("div = %s %e\n", text, d); printf("div = %s %e\n", text, d);
PGTYPESnumeric_free(value1);
PGTYPESnumeric_free(value2);
value1 = PGTYPESnumeric_from_asc("2E7", NULL); value1 = PGTYPESnumeric_from_asc("2E7", NULL);
value2 = PGTYPESnumeric_from_asc("14", NULL); value2 = PGTYPESnumeric_from_asc("14", NULL);
i = PGTYPESnumeric_to_long(value1, &l1) | PGTYPESnumeric_to_long(value2, &l2); i = PGTYPESnumeric_to_long(value1, &l1) | PGTYPESnumeric_to_long(value2, &l2);
......
...@@ -193,6 +193,11 @@ main(void) ...@@ -193,6 +193,11 @@ main(void)
printf("num[d,%d,%d]: %s\n", i, j, text); printf("num[d,%d,%d]: %s\n", i, j, text);
free(text); free(text);
} }
PGTYPESnumeric_free(a);
PGTYPESnumeric_free(s);
PGTYPESnumeric_free(m);
PGTYPESnumeric_free(d);
} }
} }
...@@ -201,7 +206,9 @@ main(void) ...@@ -201,7 +206,9 @@ main(void)
text = PGTYPESnumeric_to_asc(numarr[i], -1); text = PGTYPESnumeric_to_asc(numarr[i], -1);
printf("%d: %s\n", i, text); printf("%d: %s\n", i, text);
free(text); free(text);
PGTYPESnumeric_free(numarr[i]);
} }
free(numarr);
return (0); return (0);
} }
......
...@@ -73,5 +73,7 @@ EXEC SQL END DECLARE SECTION; ...@@ -73,5 +73,7 @@ EXEC SQL END DECLARE SECTION;
EXEC SQL DISCONNECT; EXEC SQL DISCONNECT;
free(t);
return (0); return (0);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment