mirror of
https://github.com/postgres/postgres.git
synced 2025-06-29 10:41:53 +03:00
Applied Zoltan's patch to fix a few memleaks in ecpg's pgtypeslib.
This commit is contained in:
@ -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 "postgres_fe.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -389,7 +389,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1576,8 +1576,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)
|
||||||
@ -1586,7 +1590,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)
|
|||||||
{
|
{
|
||||||
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)
|
|||||||
{
|
{
|
||||||
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)
|
|||||||
{
|
{
|
||||||
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)
|
|||||||
{
|
{
|
||||||
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 ( );}
|
|||||||
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 ( );}
|
|||||||
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 @@
|
|||||||
[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: yes
|
[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]: 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)
|
|||||||
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)
|
|||||||
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);
|
||||||
|
@ -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 ( );}
|
|||||||
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 @@
|
|||||||
[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: yes
|
[NO_PID]: ecpg_get_data on line 66: RESULT: 2369.7000000 offset: -1; array: yes
|
||||||
[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)
|
|||||||
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)
|
|||||||
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();}
|
|||||||
#line 74 "array.pgc"
|
#line 74 "array.pgc"
|
||||||
|
|
||||||
|
|
||||||
|
free(t);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -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)
|
|||||||
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)
|
|||||||
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);
|
||||||
|
@ -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)
|
|||||||
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)
|
|||||||
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;
|
|||||||
|
|
||||||
EXEC SQL DISCONNECT;
|
EXEC SQL DISCONNECT;
|
||||||
|
|
||||||
|
free(t);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user