@@ -146,12 +146,11 @@ static zend_function *odbc_result_get_constructor(zend_object *object) {
146
146
147
147
static void odbc_result_free (odbc_result * res )
148
148
{
149
- int i ;
150
-
151
149
if (res -> values ) {
152
- for ( i = 0 ; i < res -> numcols ; i ++ ) {
153
- if (res -> values [i ].value )
150
+ for ( int i = 0 ; i < res -> numcols ; i ++ ) {
151
+ if (res -> values [i ].value ) {
154
152
efree (res -> values [i ].value );
153
+ }
155
154
}
156
155
efree (res -> values );
157
156
res -> values = NULL ;
@@ -165,7 +164,6 @@ static void odbc_result_free(odbc_result *res)
165
164
SQLFreeStmt (res -> stmt ,SQL_DROP );
166
165
/* We don't want the connection to be closed after the last statement has been closed
167
166
* Connections will be closed on shutdown
168
- * zend_list_delete(res->conn_ptr->id);
169
167
*/
170
168
}
171
169
if (res -> param_info ) {
@@ -190,6 +188,7 @@ static void odbc_result_free_obj(zend_object *obj) {
190
188
191
189
PHP_ODBC_API ZEND_DECLARE_MODULE_GLOBALS (odbc )
192
190
static PHP_GINIT_FUNCTION (odbc );
191
+ static PHP_GSHUTDOWN_FUNCTION (odbc );
193
192
194
193
/* {{{ odbc_module_entry */
195
194
zend_module_entry odbc_module_entry = {
@@ -204,7 +203,7 @@ zend_module_entry odbc_module_entry = {
204
203
PHP_ODBC_VERSION ,
205
204
PHP_MODULE_GLOBALS (odbc ),
206
205
PHP_GINIT (odbc ),
207
- NULL ,
206
+ PHP_GSHUTDOWN ( odbc ) ,
208
207
NULL ,
209
208
STANDARD_MODULE_PROPERTIES_EX
210
209
};
@@ -218,12 +217,14 @@ ZEND_GET_MODULE(odbc)
218
217
#endif
219
218
220
219
static void close_results_with_connection (const odbc_connection * conn ) {
220
+ zend_ulong num_index ;
221
221
zval * p ;
222
222
223
- ZEND_HASH_FOREACH_VAL (& ODBCG (results ), p ) {
223
+ ZEND_HASH_FOREACH_NUM_KEY_VAL (& ODBCG (results ), num_index , p ) {
224
224
odbc_result * result = Z_ODBC_RESULT_P (p );
225
225
if (result -> conn_ptr == conn ) {
226
226
odbc_result_free ((odbc_result * ) p );
227
+ zend_hash_index_del (& ODBCG (results ), num_index );
227
228
}
228
229
} ZEND_HASH_FOREACH_END ();
229
230
}
@@ -443,6 +444,12 @@ static PHP_GINIT_FUNCTION(odbc)
443
444
zend_hash_init (& odbc_globals -> connections , 0 , NULL , NULL , 1 );
444
445
}
445
446
447
+ static PHP_GSHUTDOWN_FUNCTION (odbc )
448
+ {
449
+ zend_hash_destroy (& odbc_globals -> results );
450
+ zend_hash_destroy (& odbc_globals -> connections );
451
+ }
452
+
446
453
/* {{{ PHP_MINIT_FUNCTION */
447
454
PHP_MINIT_FUNCTION (odbc )
448
455
{
@@ -510,9 +517,6 @@ PHP_RSHUTDOWN_FUNCTION(odbc)
510
517
/* {{{ PHP_MSHUTDOWN_FUNCTION */
511
518
PHP_MSHUTDOWN_FUNCTION (odbc )
512
519
{
513
- zend_hash_destroy (& ODBCG (results ));
514
- zend_hash_destroy (& ODBCG (connections ));
515
-
516
520
UNREGISTER_INI_ENTRIES ();
517
521
return SUCCESS ;
518
522
}
@@ -820,6 +824,8 @@ PHP_FUNCTION(odbc_close_all)
820
824
odbc_result_free ((odbc_result * ) p );
821
825
} ZEND_HASH_FOREACH_END ();
822
826
827
+ zend_hash_clean (& ODBCG (results ));
828
+
823
829
/* Second loop through list, now close all non-persistent connections */
824
830
ZEND_HASH_FOREACH_VAL (& ODBCG (connections ), p ) {
825
831
odbc_link_free ((odbc_link * ) p );
@@ -2085,7 +2091,7 @@ PHP_FUNCTION(odbc_pconnect)
2085
2091
/* }}} */
2086
2092
2087
2093
/* {{{ odbc_sqlconnect */
2088
- bool odbc_sqlconnect (zval * zv , char * db , char * uid , char * pwd , int cur_opt , int persistent , zend_string * hash )
2094
+ bool odbc_sqlconnect (zval * zv , char * db , char * uid , char * pwd , int cur_opt , bool persistent , zend_string * hash )
2089
2095
{
2090
2096
RETCODE rc ;
2091
2097
odbc_link * link ;
@@ -2116,7 +2122,6 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, int
2116
2122
rc = SQLSetConnectOption (link -> connection -> hdbc , SQL_ODBC_CURSORS , cur_opt );
2117
2123
if (rc != SQL_SUCCESS ) { /* && rc != SQL_SUCCESS_WITH_INFO ? */
2118
2124
odbc_sql_error (link -> connection , SQL_NULL_HSTMT , "SQLSetConnectOption" );
2119
- SQLFreeConnect (link -> connection -> hdbc );
2120
2125
return false;
2121
2126
}
2122
2127
}
@@ -2190,7 +2195,6 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, int
2190
2195
#endif
2191
2196
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) {
2192
2197
odbc_sql_error (link -> connection , SQL_NULL_HSTMT , "SQLConnect" );
2193
- SQLFreeConnect (link -> connection -> hdbc );
2194
2198
return false;
2195
2199
}
2196
2200
return true;
@@ -2257,7 +2261,7 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
2257
2261
RETURN_FALSE ;
2258
2262
}
2259
2263
2260
- if (!odbc_sqlconnect (return_value , db , uid , pwd , cur_opt , 1 , hashed_details .s )) {
2264
+ if (!odbc_sqlconnect (return_value , db , uid , pwd , cur_opt , true , hashed_details .s )) {
2261
2265
smart_str_free (& hashed_details );
2262
2266
zval_ptr_dtor (return_value );
2263
2267
RETURN_FALSE ;
@@ -2332,8 +2336,9 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
2332
2336
RETURN_FALSE ;
2333
2337
}
2334
2338
2335
- if (!odbc_sqlconnect (return_value , db , uid , pwd , cur_opt , 0 , hashed_details .s )) {
2339
+ if (!odbc_sqlconnect (return_value , db , uid , pwd , cur_opt , false , hashed_details .s )) {
2336
2340
smart_str_free (& hashed_details );
2341
+ zval_ptr_dtor (return_value );
2337
2342
RETURN_FALSE ;
2338
2343
}
2339
2344
ODBCG (num_links )++ ;
@@ -3016,9 +3021,6 @@ PHP_FUNCTION(odbc_foreignkeys)
3016
3021
/* {{{ Returns a result identifier containing information about data types supported by the data source */
3017
3022
PHP_FUNCTION (odbc_gettypeinfo )
3018
3023
{
3019
- zend_value_error ("Nope" );
3020
- RETURN_THROWS ();
3021
-
3022
3024
zval * pv_conn ;
3023
3025
zend_long pv_data_type = SQL_ALL_TYPES ;
3024
3026
odbc_result * result = NULL ;
@@ -3030,8 +3032,6 @@ PHP_FUNCTION(odbc_gettypeinfo)
3030
3032
RETURN_THROWS ();
3031
3033
}
3032
3034
3033
- printf ("Hell noo" );
3034
-
3035
3035
data_type = (SQLSMALLINT ) pv_data_type ;
3036
3036
3037
3037
conn = Z_ODBC_CONNECTION_P (pv_conn );
0 commit comments