]> granicus.if.org Git - php/commitdiff
Fix leak of Pdo object if query() fails
authorNikita Popov <nikic@php.net>
Thu, 16 Apr 2015 19:00:41 +0000 (21:00 +0200)
committerNikita Popov <nikic@php.net>
Thu, 16 Apr 2015 19:08:29 +0000 (21:08 +0200)
Decref the DBH object when storing the errored query statement --
the DBH owns the stmt, so it will live long enough.

ext/pdo/pdo_dbh.c
ext/pdo/pdo_stmt.c

index a847ae5103f7560455f24e8a9f550f8e43c1dd57..9029e4a8ea5209b86fed9776b7c2e95555a2aee3 100644 (file)
@@ -1114,6 +1114,8 @@ static PHP_METHOD(PDO, query)
                /* something broke */
                dbh->query_stmt = stmt;
                ZVAL_COPY_VALUE(&dbh->query_stmt_zval, return_value);
+               Z_DELREF(stmt->database_object_handle);
+               ZVAL_UNDEF(&stmt->database_object_handle);
                PDO_HANDLE_STMT_ERR();
        } else {
                PDO_HANDLE_DBH_ERR();
index 15e489a0bd751bdfd00e47c69d99c64abc713692..3c09609fc6fa39b1f431614f5164e29940755c23 100644 (file)
@@ -803,7 +803,7 @@ static int do_fetch_func_prepare(pdo_stmt_t *stmt) /* {{{ */
 }
 /* }}} */
 
-static int do_fetch_opt_finish(pdo_stmt_t *stmt, int free_ctor_agrs) /* {{{ */
+static void do_fetch_opt_finish(pdo_stmt_t *stmt, int free_ctor_agrs) /* {{{ */
 {
        /* fci.size is used to check if it is valid */
        if (stmt->fetch.cls.fci.size && stmt->fetch.cls.fci.params) {
@@ -826,7 +826,6 @@ static int do_fetch_opt_finish(pdo_stmt_t *stmt, int free_ctor_agrs) /* {{{ */
                efree(stmt->fetch.func.values);
                stmt->fetch.func.values = NULL;
        }
-       return 1;
 }
 /* }}} */