From 9a8d15bd41687e1448bcc441adb5e183d5fdcaf2 Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Tue, 17 Aug 2010 09:36:05 +0000 Subject: [PATCH] Applied Zoltan's patch to fix a few memleaks in ecpg's pgtypeslib. --- src/interfaces/ecpg/pgtypeslib/numeric.c | 9 ++++++--- src/interfaces/ecpg/test/compat_informix/dec_test.pgc | 4 ++++ src/interfaces/ecpg/test/expected/compat_informix-dec_test.c | 4 ++++ src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c | 9 +++++---- src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr | 2 +- src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.c | 2 ++ src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.c | 10 ++++++---- src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.stderr | 2 +- src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c | 11 +++++++---- src/interfaces/ecpg/test/expected/pgtypeslib-num_test.stderr | 2 +- src/interfaces/ecpg/test/expected/pgtypeslib-num_test2.c | 7 +++++++ src/interfaces/ecpg/test/expected/sql-array.c | 2 ++ src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc | 1 + src/interfaces/ecpg/test/pgtypeslib/dt_test2.pgc | 2 ++ src/interfaces/ecpg/test/pgtypeslib/nan_test.pgc | 2 ++ src/interfaces/ecpg/test/pgtypeslib/num_test.pgc | 3 +++ src/interfaces/ecpg/test/pgtypeslib/num_test2.pgc | 7 +++++++ src/interfaces/ecpg/test/sql/array.pgc | 2 ++ 18 files changed, 63 insertions(+), 18 deletions(-) diff --git a/src/interfaces/ecpg/pgtypeslib/numeric.c b/src/interfaces/ecpg/pgtypeslib/numeric.c index 3d123489e6..001e6cc730 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.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 @@ -417,7 +417,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); } @@ -1602,8 +1602,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) @@ -1612,7 +1616,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 d1a01b556d..b374bda724 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 9bd05bc9e9..3b443e3ffd 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 a52ad13fb9..b0b3239b9f 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 6c861fac8a..41a8013f47 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: no [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 cd083f5d2e..2497eb1a23 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-nan_test.c b/src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.c index 999db79a10..077c0beee6 100644 --- a/src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.c +++ b/src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.c @@ -252,17 +252,19 @@ if (sqlca.sqlcode < 0) sqlprint ( );} #line 84 "nan_test.pgc" + PGTYPESnumeric_free(num); + { ECPGtrans(__LINE__, NULL, "rollback"); -#line 86 "nan_test.pgc" +#line 88 "nan_test.pgc" if (sqlca.sqlcode < 0) sqlprint ( );} -#line 86 "nan_test.pgc" +#line 88 "nan_test.pgc" { ECPGdisconnect(__LINE__, "CURRENT"); -#line 87 "nan_test.pgc" +#line 89 "nan_test.pgc" if (sqlca.sqlcode < 0) sqlprint ( );} -#line 87 "nan_test.pgc" +#line 89 "nan_test.pgc" return (0); diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.stderr b/src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.stderr index 41ed8fb885..d04e426aae 100644 --- a/src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.stderr +++ b/src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.stderr @@ -354,7 +354,7 @@ [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_execute on line 84: OK: CLOSE CURSOR [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]: ecpg_finish: connection regress1 closed [NO_PID]: sqlca: code: 0, state: 00000 diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c b/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c index 09554a340a..6c6eb0b23a 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 8e6257f092..9557da5e88 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: no [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 4f15226d25..83636ad880 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 ade0ccb937..cdd2bea078 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 3ed2061454..4e3c440443 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 27d616751d..5ab2dfeccf 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/nan_test.pgc b/src/interfaces/ecpg/test/pgtypeslib/nan_test.pgc index 304b43816a..a5cbe296a9 100644 --- a/src/interfaces/ecpg/test/pgtypeslib/nan_test.pgc +++ b/src/interfaces/ecpg/test/pgtypeslib/nan_test.pgc @@ -83,6 +83,8 @@ main(void) } exec sql close cur1; + PGTYPESnumeric_free(num); + exec sql rollback; exec sql disconnect; diff --git a/src/interfaces/ecpg/test/pgtypeslib/num_test.pgc b/src/interfaces/ecpg/test/pgtypeslib/num_test.pgc index 3d62e694b7..fcdc396435 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 0b2a2e654c..2ac666f7c0 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 d589a242f5..d74a1354e5 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); } -- 2.11.0