Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index ec5f33f..c42bf08 100644
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -537,6 +537,16 @@ static PHP_METHOD(PDO, prepare)
PDO_HANDLE_DBH_ERR();
RETURN_FALSE;
}
+
+ /* this is a tricky way to make sure stmt object is always dtor before dbh */
+ if (UNEXPECTED(Z_OBJ_HANDLE_P(return_value) < Z_OBJ_HANDLE_P(getThis()))) {
+ int handle = Z_OBJ_HANDLE_P(getThis());
+ zend_object_store_set_object(return_value, Z_OBJ_P(getThis()));
+ zend_object_store_set_object(getThis(), Z_OBJ_P(return_value));
+ Z_OBJ_HANDLE_P(getThis()) = Z_OBJ_HANDLE_P(return_value);
+ Z_OBJ_HANDLE_P(return_value) = handle;
+ }
+
stmt = Z_PDO_STMT_P(return_value);
/* unconditionally keep this for later reference */
@@ -1075,6 +1085,15 @@ static PHP_METHOD(PDO, query)
}
return;
}
+ /* this is a tricky way to make sure stmt object is always dtor before dbh */
+ if (UNEXPECTED(Z_OBJ_HANDLE_P(return_value) < Z_OBJ_HANDLE_P(getThis()))) {
+ int handle = Z_OBJ_HANDLE_P(getThis());
+ zend_object_store_set_object(return_value, Z_OBJ_P(getThis()));
+ zend_object_store_set_object(getThis(), Z_OBJ_P(return_value));
+ Z_OBJ_HANDLE_P(getThis()) = Z_OBJ_HANDLE_P(return_value);
+ Z_OBJ_HANDLE_P(return_value) = handle;
+ }
+
stmt = Z_PDO_STMT_P(return_value);
/* unconditionally keep this for later reference */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.