From: Michael Meskes Date: Thu, 15 Oct 2009 10:20:15 +0000 (+0000) Subject: Made ECPG more robust against applications freeing strings, based on X-Git-Tag: REL8_5_ALPHA2~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d9623859e8af4a0bf8e47970c544dcb4d27028ec;p=postgresql Made ECPG more robust against applications freeing strings, based on patch send in by Boszormenyi Zoltan . --- diff --git a/src/interfaces/ecpg/ChangeLog b/src/interfaces/ecpg/ChangeLog index 1f803c9f9e..9537e8da6f 100644 --- a/src/interfaces/ecpg/ChangeLog +++ b/src/interfaces/ecpg/ChangeLog @@ -2438,6 +2438,11 @@ Thu, 01 Oct 2009 19:31:57 +0200 - Applied patch by Boszormenyi Zoltan to fix memory leak in decimal handling. + +Thu, 15 Oct 2009 12:15:31 +0200 + + - Made ECPG more robust against applications freeing strings, based on + patch send in by Boszormenyi Zoltan . - Set ecpg library version to 6.2. - Set compat library version to 3.2. - Set ecpg version to 4.6. diff --git a/src/interfaces/ecpg/ecpglib/prepare.c b/src/interfaces/ecpg/ecpglib/prepare.c index 5be2ac0499..17b2cc05b1 100644 --- a/src/interfaces/ecpg/ecpglib/prepare.c +++ b/src/interfaces/ecpg/ecpglib/prepare.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.32 2009/07/22 11:07:02 mha Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.33 2009/10/15 10:20:15 meskes Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -152,7 +152,7 @@ ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, c replace_variables(&(stmt->command), lineno); /* add prepared statement to our list */ - this->name = (char *) name; + this->name = ecpg_strdup(name, lineno); this->stmt = stmt; /* and finally really prepare the statement */ @@ -160,6 +160,7 @@ ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, c if (!ecpg_check_PQresult(query, stmt->lineno, stmt->connection->connection, stmt->compat)) { ecpg_free(stmt->command); + ecpg_free(this->name); ecpg_free(this); ecpg_free(stmt); return false; @@ -238,6 +239,7 @@ deallocate_one(int lineno, enum COMPAT_MODE c, struct connection * con, struct p /* okay, free all the resources */ ecpg_free(this->stmt->command); ecpg_free(this->stmt); + ecpg_free(this->name); if (prev != NULL) prev->next = this->next; else