From d3bbd2b91438bf7bdbcc235335e61d671b4e6cb5 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Sun, 26 Jan 2025 11:02:13 -0400 Subject: [PATCH] Fix crash in PDO_ODBC statement dtor Port of 2ae897fff7af3a794a31a8aeeeeb4f21f6a41393 to PDO_ODBC. --- ext/pdo_odbc/odbc_stmt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ext/pdo_odbc/odbc_stmt.c b/ext/pdo_odbc/odbc_stmt.c index 1df4e22571a7..4bf7162ea06e 100644 --- a/ext/pdo_odbc/odbc_stmt.c +++ b/ext/pdo_odbc/odbc_stmt.c @@ -136,7 +136,11 @@ static int odbc_stmt_dtor(pdo_stmt_t *stmt) { pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data; - if (S->stmt != SQL_NULL_HANDLE) { + // TODO: Factor this out; pg/mysql/firebird do the same thing + bool server_obj_usable = !Z_ISUNDEF(stmt->database_object_handle) + && IS_OBJ_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE(stmt->database_object_handle)]) + && !(OBJ_FLAGS(Z_OBJ(stmt->database_object_handle)) & IS_OBJ_FREE_CALLED); + if (S->stmt != SQL_NULL_HANDLE && server_obj_usable) { if (stmt->executed) { SQLCloseCursor(S->stmt); }