fix leak in pg_copy_to() when invalid resource was passed

This commit is contained in:
Antony Dovgal 2006-09-06 12:40:56 +00:00
parent 7d7f84562c
commit 37635d93e6

View file

@ -3309,12 +3309,13 @@ PHP_FUNCTION(pg_copy_to)
if (!pg_delim) {
pg_delim = "\t";
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
if (!pg_null_as) {
pg_null_as = safe_estrdup("\\\\N");
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
query = (char *)emalloc(strlen(query_template) + strlen(table_name) + strlen(pg_null_as) + 1);
sprintf(query, "COPY \"%s\" TO STDOUT DELIMITERS '%c' WITH NULL AS '%s'",
table_name, *pg_delim, pg_null_as);