Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fa0dc92

Browse files
author
Michael Meskes
committed
- Fixed segfault in ecpg when using an array element.
- Free all memory in auto-prepare mode.
1 parent 8d36372 commit fa0dc92

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

src/interfaces/ecpg/ChangeLog

+7
Original file line numberDiff line numberDiff line change
@@ -2301,3 +2301,10 @@ Tue, 15 Jan 2008 11:26:14 +0100
23012301
- Set compat library version to 3.0.
23022302
- Set ecpg library version to 6.0.
23032303
- Set ecpg version to 4.4.
2304+
2305+
Wed, 06 Feb 2008 09:04:48 +0100
2306+
2307+
- Fixed segfault in ecpg when using an array element.
2308+
- Free all memory in auto-prepare mode.
2309+
2310+

src/interfaces/ecpg/ecpglib/execute.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.75 2008/01/15 10:31:47 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.76 2008/02/07 11:09:12 meskes Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -1489,7 +1489,7 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char
14891489
*/
14901490
if (statement_type == ECPGst_prepnormal)
14911491
{
1492-
if (!ecpg_auto_prepare(lineno, connection_name, questionmarks, &prepname, query))
1492+
if (!ecpg_auto_prepare(lineno, connection_name, compat, questionmarks, &prepname, query))
14931493
return (false);
14941494

14951495
/*

src/interfaces/ecpg/ecpglib/extern.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.33 2008/01/15 10:31:47 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.34 2008/02/07 11:09:12 meskes Exp $ */
22

33
#ifndef _ECPG_LIB_EXTERN_H
44
#define _ECPG_LIB_EXTERN_H
@@ -146,7 +146,7 @@ void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat);
146146
char *ecpg_prepared(const char *, struct connection *, int);
147147
bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection * conn);
148148
void ecpg_log(const char *format,...);
149-
bool ecpg_auto_prepare(int, const char *, const int, char **, const char *);
149+
bool ecpg_auto_prepare(int, const char *, int, const int, char **, const char *);
150150
void ecpg_init_sqlca(struct sqlca_t * sqlca);
151151

152152
/* SQLSTATE values generated or processed by ecpglib (intentionally

src/interfaces/ecpg/ecpglib/prepare.c

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.25 2007/11/15 22:25:17 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.26 2008/02/07 11:09:13 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -373,30 +373,26 @@ SearchStmtCache(const char *ecpgQuery)
373373
* OR negative error code
374374
*/
375375
static int
376-
ecpg_freeStmtCacheEntry(int entNo) /* entry # to free */
376+
ecpg_freeStmtCacheEntry(int lineno, int compat, int entNo) /* entry # to free */
377377
{
378378
stmtCacheEntry *entry;
379-
PGresult *results;
380-
char deallocText[100];
381379
struct connection *con;
380+
struct prepared_statement *this, *prev;
382381

383382
entry = &stmtCacheEntries[entNo];
384383
if (!entry->stmtID[0]) /* return if the entry isn't in use */
385384
return (0);
386385

387386
con = ecpg_get_connection(entry->connection);
388-
/* free the server resources for the statement */
389-
ecpg_log("ecpg_freeStmtCacheEntry line %d: deallocate %s, cache entry #%d\n", entry->lineno, entry->stmtID, entNo);
390-
sprintf(deallocText, "DEALLOCATE PREPARE %s", entry->stmtID);
391-
results = PQexec(con->connection, deallocText);
392387

393-
if (!ecpg_check_PQresult(results, entry->lineno, con->connection, ECPG_COMPAT_PGSQL))
388+
/* free the 'prepared_statement' list entry */
389+
this = find_prepared_statement(entry->stmtID, con, &prev);
390+
if (this && !deallocate_one(lineno, compat, con, prev, this))
394391
return (-1);
395-
PQclear(results);
396392

397393
entry->stmtID[0] = '\0';
398394

399-
/* free the memory used by the cache entry */
395+
/* free the memory used by the cache entry */
400396
if (entry->ecpgQuery)
401397
{
402398
ecpg_free(entry->ecpgQuery);
@@ -414,6 +410,7 @@ static int
414410
AddStmtToCache(int lineno, /* line # of statement */
415411
char *stmtID, /* statement ID */
416412
const char *connection, /* connection */
413+
int compat, /* compatibility level */
417414
const char *ecpgQuery) /* query */
418415
{
419416
int ix,
@@ -444,7 +441,7 @@ AddStmtToCache(int lineno, /* line # of statement */
444441
entNo = luEntNo; /* re-use the 'least used' entry */
445442

446443
/* 'entNo' is the entry to use - make sure its free */
447-
if (ecpg_freeStmtCacheEntry(entNo) < 0)
444+
if (ecpg_freeStmtCacheEntry(lineno, compat, entNo) < 0)
448445
return (-1);
449446

450447
/* add the query to the entry */
@@ -460,7 +457,7 @@ AddStmtToCache(int lineno, /* line # of statement */
460457

461458
/* handle cache and preparation of statments in auto-prepare mode */
462459
bool
463-
ecpg_auto_prepare(int lineno, const char *connection_name, const int questionmarks, char **name, const char *query)
460+
ecpg_auto_prepare(int lineno, const char *connection_name, int compat, const int questionmarks, char **name, const char *query)
464461
{
465462
int entNo;
466463

@@ -483,7 +480,7 @@ ecpg_auto_prepare(int lineno, const char *connection_name, const int questionmar
483480

484481
if (!ECPGprepare(lineno, connection_name, questionmarks, ecpg_strdup(*name, lineno), query))
485482
return (false);
486-
if (AddStmtToCache(lineno, *name, connection_name, query) < 0)
483+
if (AddStmtToCache(lineno, *name, connection_name, compat, query) < 0)
487484
return (false);
488485
}
489486

src/interfaces/ecpg/preproc/variable.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/variable.c,v 1.43 2007/12/21 14:33:20 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/variable.c,v 1.44 2008/02/07 11:09:13 meskes Exp $ */
22

33
#include "postgres_fe.h"
44

@@ -237,7 +237,7 @@ find_variable(char *name)
237237
case ECPGt_union:
238238
return (new_variable(name, ECPGmake_struct_type(p->type->u.element->u.members, p->type->u.element->type, p->type->u.element->struct_sizeof), p->brace_level));
239239
default:
240-
return (new_variable(name, ECPGmake_simple_type(p->type->u.element->type, p->type->u.element->size, p->type->u.element->u.element->lineno), p->brace_level));
240+
return (new_variable(name, ECPGmake_simple_type(p->type->u.element->type, p->type->u.element->size, p->type->u.element->lineno), p->brace_level));
241241
}
242242
}
243243
}

0 commit comments

Comments
 (0)