Skip to content

Commit 8f743f1

Browse files
committed
Address code review comments
1 parent b273702 commit 8f743f1

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

ext/odbc/php_odbc.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,11 @@ static zend_function *odbc_result_get_constructor(zend_object *object) {
146146

147147
static void odbc_result_free(odbc_result *res)
148148
{
149-
int i;
150-
151149
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) {
154152
efree(res->values[i].value);
153+
}
155154
}
156155
efree(res->values);
157156
res->values = NULL;
@@ -165,7 +164,6 @@ static void odbc_result_free(odbc_result *res)
165164
SQLFreeStmt(res->stmt,SQL_DROP);
166165
/* We don't want the connection to be closed after the last statement has been closed
167166
* Connections will be closed on shutdown
168-
* zend_list_delete(res->conn_ptr->id);
169167
*/
170168
}
171169
if (res->param_info) {
@@ -190,6 +188,7 @@ static void odbc_result_free_obj(zend_object *obj) {
190188

191189
PHP_ODBC_API ZEND_DECLARE_MODULE_GLOBALS(odbc)
192190
static PHP_GINIT_FUNCTION(odbc);
191+
static PHP_GSHUTDOWN_FUNCTION(odbc);
193192

194193
/* {{{ odbc_module_entry */
195194
zend_module_entry odbc_module_entry = {
@@ -204,7 +203,7 @@ zend_module_entry odbc_module_entry = {
204203
PHP_ODBC_VERSION,
205204
PHP_MODULE_GLOBALS(odbc),
206205
PHP_GINIT(odbc),
207-
NULL,
206+
PHP_GSHUTDOWN(odbc),
208207
NULL,
209208
STANDARD_MODULE_PROPERTIES_EX
210209
};
@@ -218,12 +217,14 @@ ZEND_GET_MODULE(odbc)
218217
#endif
219218

220219
static void close_results_with_connection(const odbc_connection *conn) {
220+
zend_ulong num_index;
221221
zval *p;
222222

223-
ZEND_HASH_FOREACH_VAL(&ODBCG(results), p) {
223+
ZEND_HASH_FOREACH_NUM_KEY_VAL(&ODBCG(results), num_index, p) {
224224
odbc_result *result = Z_ODBC_RESULT_P(p);
225225
if (result->conn_ptr == conn) {
226226
odbc_result_free((odbc_result*) p);
227+
zend_hash_index_del(&ODBCG(results), num_index);
227228
}
228229
} ZEND_HASH_FOREACH_END();
229230
}
@@ -443,6 +444,12 @@ static PHP_GINIT_FUNCTION(odbc)
443444
zend_hash_init(&odbc_globals->connections, 0, NULL, NULL, 1);
444445
}
445446

447+
static PHP_GSHUTDOWN_FUNCTION(odbc)
448+
{
449+
zend_hash_destroy(&odbc_globals->results);
450+
zend_hash_destroy(&odbc_globals->connections);
451+
}
452+
446453
/* {{{ PHP_MINIT_FUNCTION */
447454
PHP_MINIT_FUNCTION(odbc)
448455
{
@@ -510,9 +517,6 @@ PHP_RSHUTDOWN_FUNCTION(odbc)
510517
/* {{{ PHP_MSHUTDOWN_FUNCTION */
511518
PHP_MSHUTDOWN_FUNCTION(odbc)
512519
{
513-
zend_hash_destroy(&ODBCG(results));
514-
zend_hash_destroy(&ODBCG(connections));
515-
516520
UNREGISTER_INI_ENTRIES();
517521
return SUCCESS;
518522
}
@@ -820,6 +824,8 @@ PHP_FUNCTION(odbc_close_all)
820824
odbc_result_free((odbc_result*) p);
821825
} ZEND_HASH_FOREACH_END();
822826

827+
zend_hash_clean(&ODBCG(results));
828+
823829
/* Second loop through list, now close all non-persistent connections */
824830
ZEND_HASH_FOREACH_VAL(&ODBCG(connections), p) {
825831
odbc_link_free((odbc_link*) p);
@@ -2085,7 +2091,7 @@ PHP_FUNCTION(odbc_pconnect)
20852091
/* }}} */
20862092

20872093
/* {{{ 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)
20892095
{
20902096
RETCODE rc;
20912097
odbc_link *link;
@@ -2116,7 +2122,6 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, int
21162122
rc = SQLSetConnectOption(link->connection->hdbc, SQL_ODBC_CURSORS, cur_opt);
21172123
if (rc != SQL_SUCCESS) { /* && rc != SQL_SUCCESS_WITH_INFO ? */
21182124
odbc_sql_error(link->connection, SQL_NULL_HSTMT, "SQLSetConnectOption");
2119-
SQLFreeConnect(link->connection->hdbc);
21202125
return false;
21212126
}
21222127
}
@@ -2190,7 +2195,6 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, int
21902195
#endif
21912196
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
21922197
odbc_sql_error(link->connection, SQL_NULL_HSTMT, "SQLConnect");
2193-
SQLFreeConnect(link->connection->hdbc);
21942198
return false;
21952199
}
21962200
return true;
@@ -2257,7 +2261,7 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
22572261
RETURN_FALSE;
22582262
}
22592263

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)) {
22612265
smart_str_free(&hashed_details);
22622266
zval_ptr_dtor(return_value);
22632267
RETURN_FALSE;
@@ -2332,8 +2336,9 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
23322336
RETURN_FALSE;
23332337
}
23342338

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)) {
23362340
smart_str_free(&hashed_details);
2341+
zval_ptr_dtor(return_value);
23372342
RETURN_FALSE;
23382343
}
23392344
ODBCG(num_links)++;
@@ -3016,9 +3021,6 @@ PHP_FUNCTION(odbc_foreignkeys)
30163021
/* {{{ Returns a result identifier containing information about data types supported by the data source */
30173022
PHP_FUNCTION(odbc_gettypeinfo)
30183023
{
3019-
zend_value_error("Nope");
3020-
RETURN_THROWS();
3021-
30223024
zval *pv_conn;
30233025
zend_long pv_data_type = SQL_ALL_TYPES;
30243026
odbc_result *result = NULL;
@@ -3030,8 +3032,6 @@ PHP_FUNCTION(odbc_gettypeinfo)
30303032
RETURN_THROWS();
30313033
}
30323034

3033-
printf("Hell noo");
3034-
30353035
data_type = (SQLSMALLINT) pv_data_type;
30363036

30373037
conn = Z_ODBC_CONNECTION_P(pv_conn);

0 commit comments

Comments
 (0)