diff options
| author | Michael Meskes <meskes@postgresql.org> | 2010-08-17 11:06:26 +0000 | 
|---|---|---|
| committer | Michael Meskes <meskes@postgresql.org> | 2010-08-17 11:06:26 +0000 | 
| commit | 277633b7e85167646a4fbd09aa3d0679fef154d6 (patch) | |
| tree | 114ffda7e8d8d7593440ce2f222ae45b8fb971e7 /src | |
| parent | db7fe0de6280ea71c0ce949ee4a00da2af4bf2d8 (diff) | |
Applied Zoltan's patch to fix a few memleaks in ecpg's pgtypeslib.
Diffstat (limited to 'src')
18 files changed, 63 insertions, 18 deletions
| diff --git a/src/interfaces/ecpg/pgtypeslib/numeric.c b/src/interfaces/ecpg/pgtypeslib/numeric.c index 3d123489e60..6989b664514 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.35.6.1 2010/08/17 11:06:26 meskes Exp $ */  #include "postgres_fe.h"  #include <ctype.h> @@ -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 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 6c861fac8a4..41a8013f47a 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 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-nan_test.c b/src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.c index 999db79a107..077c0beee6b 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 41ed8fb885b..d04e426aaeb 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 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 8e6257f0929..9557da5e880 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 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/nan_test.pgc b/src/interfaces/ecpg/test/pgtypeslib/nan_test.pgc index 304b43816ae..a5cbe296a97 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 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);  } | 
