From: Anatol Belski Date: Sat, 3 Sep 2016 14:59:17 +0000 (+0200) Subject: fix leak and error check order X-Git-Tag: php-7.1.0RC2~56^2~18^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9513187deec82ffb2f56b86ce5f940d1fb5329f9;p=php fix leak and error check order --- diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 8f3518d7c2..f05efc7939 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -4043,12 +4043,12 @@ PHP_FUNCTION(pg_copy_to) &pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len) == FAILURE) { return; } - if (!pg_delim) { - pg_delim = "\t"; - } ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); + if (!pg_delim) { + pg_delim = "\t"; + } if (!pg_null_as) { pg_null_as = safe_estrdup("\\\\N"); free_pg_null = 1; @@ -4176,6 +4176,9 @@ PHP_FUNCTION(pg_copy_from) &pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len) == FAILURE) { return; } + + ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); + if (!pg_delim) { pg_delim = "\t"; } @@ -4184,8 +4187,6 @@ PHP_FUNCTION(pg_copy_from) pg_null_as_free = 1; } - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); - spprintf(&query, 0, "COPY %s FROM STDIN DELIMITERS E'%c' WITH NULL AS E'%s'", table_name, *pg_delim, pg_null_as); while ((pgsql_result = PQgetResult(pgsql))) { PQclear(pgsql_result);