From 17b877a77242dfcfc6436340b8a9d804a60bf2c7 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Tue, 5 Jul 2005 12:45:39 +0000 Subject: - Fixed memory corruption in pg_copy_from() in case the as_null parameter was passed. (Derick) --- ext/pgsql/pgsql.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'ext/pgsql') diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 2fa3657b25..ec863185e8 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -3280,6 +3280,7 @@ PHP_FUNCTION(pg_copy_from) zval **tmp; char *table_name, *pg_delim = NULL, *pg_null_as = NULL; int table_name_len, pg_delim_len, pg_null_as_len; + int pg_null_as_free = 0; char *query; char *query_template = "COPY \"\" FROM STDIN DELIMITERS ':' WITH NULL AS ''"; HashPosition pos; @@ -3299,6 +3300,7 @@ PHP_FUNCTION(pg_copy_from) } if (!pg_null_as) { pg_null_as = safe_estrdup("\\\\N"); + pg_null_as_free = 1; } ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); @@ -3311,7 +3313,9 @@ PHP_FUNCTION(pg_copy_from) } pgsql_result = PQexec(pgsql, query); - efree(pg_null_as); + if (pg_null_as_free) { + efree(pg_null_as); + } efree(query); if (pgsql_result) { -- cgit v1.2.1