On Sun, 13 Nov 2005, Peter Eisentraut wrote:
! (*stmt)-command = (char *)query;
(*stmt)-connection = connection;
(*stmt)-lineno = lineno;
(*stmt)-compat = compat;
This sort of cheating should be avoided.
According to Peter's comment, revised patch is attached. It duplicates the
values of the query string and free it at the end of the query. There is
another question -- seems we allow strdup() fails silently in various
places. Shall we do something about it?
Regards,
Qingqing
---
Index: ecpglib/descriptor.c
===
RCS file: /projects/cvsroot/pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v
retrieving revision 1.12
diff -c -r1.12 descriptor.c
*** ecpglib/descriptor.c29 Aug 2004 05:06:59 - 1.12
--- ecpglib/descriptor.c16 Nov 2005 00:40:57 -
***
*** 49,55
}
bool
! ECPGget_desc_header(int lineno, char *desc_name, int *count)
{
PGresult *ECPGresult;
struct sqlca_t *sqlca = ECPGget_sqlca();
--- 49,55
}
bool
! ECPGget_desc_header(int lineno, const char *desc_name, int *count)
{
PGresult *ECPGresult;
struct sqlca_t *sqlca = ECPGget_sqlca();
***
*** 188,194
}
bool
! ECPGget_desc(int lineno, char *desc_name, int index,...)
{
va_list args;
PGresult *ECPGresult;
--- 188,194
}
bool
! ECPGget_desc(int lineno, const char *desc_name, int index,...)
{
va_list args;
PGresult *ECPGresult;
***
*** 431,437
}
bool
! ECPGset_desc_header(int lineno, char *desc_name, int count)
{
struct descriptor *desc;
--- 431,437
}
bool
! ECPGset_desc_header(int lineno, const char *desc_name, int count)
{
struct descriptor *desc;
***
*** 452,458
}
bool
! ECPGset_desc(int lineno, char *desc_name, int index,...)
{
va_list args;
struct descriptor *desc;
--- 452,458
}
bool
! ECPGset_desc(int lineno, const char *desc_name, int index,...)
{
va_list args;
struct descriptor *desc;
Index: ecpglib/execute.c
===
RCS file: /projects/cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v
retrieving revision 1.43
diff -c -r1.43 execute.c
*** ecpglib/execute.c 15 Oct 2005 02:49:47 - 1.43
--- ecpglib/execute.c 16 Nov 2005 00:40:57 -
***
*** 141,147
* ind_offset - indicator offset
*/
static bool
! create_statement(int lineno, int compat, int force_indicator, struct
connection * connection, struct statement ** stmt, char *query, va_list ap)
{
struct variable **list = ((*stmt)-inlist);
enum ECPGttype type;
--- 141,148
* ind_offset - indicator offset
*/
static bool
! create_statement(int lineno, int compat, int force_indicator, struct
connection * connection, struct statement ** stmt, const char
! *query, va_list ap)
{
struct variable **list = ((*stmt)-inlist);
enum ECPGttype type;
***
*** 149,155
if (!(*stmt = (struct statement *) ECPGalloc(sizeof(struct statement),
lineno)))
return false;
! (*stmt)-command = query;
(*stmt)-connection = connection;
(*stmt)-lineno = lineno;
(*stmt)-compat = compat;
--- 150,156
if (!(*stmt = (struct statement *) ECPGalloc(sizeof(struct statement),
lineno)))
return false;
! (*stmt)-command = strdup(query);
(*stmt)-connection = connection;
(*stmt)-lineno = lineno;
(*stmt)-compat = compat;
***
*** 224,229
--- 225,231
return;
free_variable(stmt-inlist);
free_variable(stmt-outlist);
+ ECPGfree(stmt-command);
ECPGfree(stmt);
}
***
*** 1359,1365
}
bool
! ECPGdo(int lineno, int compat, int force_indicator, const char
*connection_name, char *query,...)
{
va_list args;
struct statement *stmt;
--- 1361,1367
}
bool
! ECPGdo(int lineno, int compat, int force_indicator, const char
*connection_name, const char *query,...)
{
va_list args;
struct statement *stmt;
***
*** 1417,1423
ECPGdo_descriptor(int line, const char *connection,
const char *descriptor, const char *query)
{
! return ECPGdo(line, ECPG_COMPAT_PGSQL, true, connection, (char *)
query, ECPGt_EOIT,
ECPGt_descriptor, descriptor, 0L, 0L, 0L,
ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L,
ECPGt_EORT);
}
--- 1419,1425
ECPGdo_descriptor(int line, const char *connection,
const char *descriptor, const char *query)
{
! return ECPGdo(line, ECPG_COMPAT_PGSQL, true,