]> granicus.if.org Git - php/commitdiff
fix leak and error check order
authorAnatol Belski <ab@php.net>
Sat, 3 Sep 2016 14:59:17 +0000 (16:59 +0200)
committerAnatol Belski <ab@php.net>
Sat, 3 Sep 2016 14:59:17 +0000 (16:59 +0200)
ext/pgsql/pgsql.c

index 8f3518d7c29686f319e7ada2603ca92e0b5ed85d..f05efc7939716dbf30afff9818d891877249aa80 100644 (file)
@@ -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);