]> granicus.if.org Git - php/commitdiff
Consistent error handling in mysqli_poll
authorDharman <tekiela246@gmail.com>
Wed, 14 Oct 2020 22:17:48 +0000 (23:17 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 26 Oct 2020 15:25:25 +0000 (16:25 +0100)
This error condition should not actually be reachable, but change
it to be consistent with the other ones.

Also fix a memory leak.

Closes GH-6340.

ext/mysqli/mysqli_nonapi.c
ext/mysqli/mysqli_warning.c
ext/mysqli/tests/mysqli_poll.phpt

index 4ffe1c1307b312a6d50aba9f757d531c2b2e1e7c..364638c44a0770f4cf07593bcd2857374b479409 100644 (file)
@@ -740,7 +740,7 @@ static int mysqlnd_zval_array_to_mysqlnd_array(zval *in_array, MYSQLND ***out_ar
                        MYSQLI_RESOURCE *my_res;
                        mysqli_object *intern = Z_MYSQLI_P(elem);
                        if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {
-                               zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(intern->zo.ce->name));
+                               zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(intern->zo.ce->name));
                                return FAILURE;
                        }
                        mysql = (MY_MYSQL*) my_res->ptr;
@@ -761,12 +761,11 @@ static int mysqlnd_zval_array_from_mysqlnd_array(MYSQLND **in_array, zval *out_a
        MYSQLND **p = in_array;
        zval dest_array;
        zval *elem, *dest_elem;
-       int ret = 0, i = 0;
+       int ret = 0;
 
        array_init_size(&dest_array, zend_hash_num_elements(Z_ARRVAL_P(out_array)));
 
        ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(out_array), elem) {
-               i++;
                if (Z_TYPE_P(elem) != IS_OBJECT ||
                                !instanceof_function(Z_OBJCE_P(elem), mysqli_link_class_entry)) {
                        continue;
@@ -776,8 +775,8 @@ static int mysqlnd_zval_array_from_mysqlnd_array(MYSQLND **in_array, zval *out_a
                        MYSQLI_RESOURCE *my_res;
                        mysqli_object *intern = Z_MYSQLI_P(elem);
                        if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {
-                               php_error_docref(NULL, E_WARNING, "[%d] Couldn't fetch %s", i, ZSTR_VAL(intern->zo.ce->name));
-                               continue;
+                               zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(intern->zo.ce->name));
+                               return FAILURE;
                        }
                        mysql = (MY_MYSQL *) my_res->ptr;
                        if (mysql->mysql == *p) {
@@ -867,6 +866,7 @@ PHP_FUNCTION(mysqli_poll)
        if (e_array != NULL) {
                if (mysqlnd_zval_array_to_mysqlnd_array(e_array, &new_e_array) == FAILURE) {
                        efree(new_e_array);
+                       efree(new_r_array);
                        RETURN_THROWS();
                }
        }
index c99b3df5df894c57d7d8f3609535543f26923514..7b1552e5ace47c60079110966f42dfc92f40c8a3 100644 (file)
@@ -201,7 +201,7 @@ static int mysqli_warning_message(mysqli_object *obj, zval *retval, zend_bool qu
 
        if (!obj->ptr || !((MYSQLI_RESOURCE *)(obj->ptr))->ptr) {
                if (!quiet) {
-                       zend_throw_error(NULL, "Couldn't fetch %s", ZSTR_VAL(obj->zo.ce->name));
+                       zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(obj->zo.ce->name));
                }
 
                return FAILURE;
@@ -221,7 +221,7 @@ static int mysqli_warning_sqlstate(mysqli_object *obj, zval *retval, zend_bool q
 
        if (!obj->ptr || !((MYSQLI_RESOURCE *)(obj->ptr))->ptr) {
                if (!quiet) {
-                       zend_throw_error(NULL, "Couldn't fetch %s", ZSTR_VAL(obj->zo.ce->name));
+                       zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(obj->zo.ce->name));
                }
 
                return FAILURE;
@@ -241,7 +241,7 @@ static int mysqli_warning_errno(mysqli_object *obj, zval *retval, zend_bool quie
 
        if (!obj->ptr || !((MYSQLI_RESOURCE *)(obj->ptr))->ptr) {
                if (!quiet) {
-                       zend_throw_error(NULL, "Couldn't fetch %s", ZSTR_VAL(obj->zo.ce->name));
+                       zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(obj->zo.ce->name));
                }
 
                return FAILURE;
index 7ff77f71c8e902d7b272b5ef54e25673026ae59d..615c027d68482d8fb7cd550f876949ace03f9bf3 100644 (file)
@@ -40,6 +40,14 @@ if (!$IS_MYSQLND)
         echo $e->getMessage() . \PHP_EOL;
     }
 
+    $link->close();
+    $read[0] = get_connection();
+    try {
+        mysqli_poll($read, $error, $reject, 0, 1);
+    } catch (\Error $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
+
     function poll_async($offset, $link, $links, $errors, $reject, $exp_ready, $use_oo_syntax) {
 
         if ($exp_ready !== ($tmp = mysqli_poll($links, $errors, $reject, 0, 1000)))
@@ -116,6 +124,7 @@ if (!$IS_MYSQLND)
 --EXPECTF--
 mysqli_poll(): Argument #4 ($seconds) must be greater than or equal to 0
 mysqli_poll(): Argument #5 ($microseconds) must be greater than or equal to 0
+mysqli object is already closed
 [012 + 6] Rejecting thread %d: 0/
 [013 + 6] Rejecting thread %d: 0/
 [014 + 6] Rejecting thread %d: 0/