2067da
From 657494235eafe048e9fa6a19dcdb3c73a0cbe6ec Mon Sep 17 00:00:00 2001
2067da
From: Remi Collet <fedora@famillecollet.com>
2067da
Date: Thu, 27 Sep 2012 13:45:32 +0200
2067da
Subject: [PATCH] Fixed bug #63171, script hangs if odbc call during timeout
2067da
2067da
---
2067da
 ext/odbc/php_odbc.c |   21 ++++++++++++++-------
2067da
 1 file changed, 14 insertions(+), 7 deletions(-)
2067da
2067da
diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c
2067da
index 52d46b2..2169e65 100644
2067da
--- a/ext/odbc/php_odbc.c
2067da
+++ b/ext/odbc/php_odbc.c
2067da
@@ -431,7 +431,8 @@ static void _free_odbc_result(zend_rsrc_list_entry *rsrc TSRMLS_DC)
2067da
 			efree(res->values);
2067da
 			res->values = NULL;
2067da
 		}
2067da
-		if (res->stmt) {
2067da
+		/* If aborted via timer expiration, don't try to call any unixODBC function */
2067da
+		if (res->stmt && !(PG(connection_status) & PHP_CONNECTION_TIMEOUT)) {
2067da
 #if defined(HAVE_SOLID) || defined(HAVE_SOLID_30) || defined(HAVE_SOLID_35)
2067da
 			SQLTransact(res->conn_ptr->henv, res->conn_ptr->hdbc,
2067da
 						(SQLUSMALLINT) SQL_COMMIT);
2067da
@@ -484,9 +485,12 @@ static void _close_odbc_conn(zend_rsrc_list_entry *rsrc TSRMLS_DC)
2067da
 		}
2067da
 	}
2067da
 
2067da
-   	safe_odbc_disconnect(conn->hdbc);
2067da
-	SQLFreeConnect(conn->hdbc);
2067da
-	SQLFreeEnv(conn->henv);
2067da
+	/* If aborted via timer expiration, don't try to call any unixODBC function */
2067da
+	if (!(PG(connection_status) & PHP_CONNECTION_TIMEOUT)) {
2067da
+		safe_odbc_disconnect(conn->hdbc);
2067da
+		SQLFreeConnect(conn->hdbc);
2067da
+		SQLFreeEnv(conn->henv);
2067da
+	}
2067da
 	efree(conn);
2067da
 	ODBCG(num_links)--;
2067da
 }
2067da
@@ -512,9 +516,12 @@ static void _close_odbc_pconn(zend_rsrc_list_entry *rsrc TSRMLS_DC)
2067da
 		}
2067da
 	}
2067da
 	
2067da
-	safe_odbc_disconnect(conn->hdbc);
2067da
-	SQLFreeConnect(conn->hdbc);
2067da
-	SQLFreeEnv(conn->henv);
2067da
+	/* If aborted via timer expiration, don't try to call any unixODBC function */
2067da
+	if (!(PG(connection_status) & PHP_CONNECTION_TIMEOUT)) {
2067da
+		safe_odbc_disconnect(conn->hdbc);
2067da
+		SQLFreeConnect(conn->hdbc);
2067da
+		SQLFreeEnv(conn->henv);
2067da
+	}
2067da
 	free(conn);
2067da
 
2067da
 	ODBCG(num_links)--;
2067da
-- 
2067da
1.7.10
2067da