From: Andrey Hristov Date: Thu, 14 Jan 2016 21:36:44 +0000 (+0100) Subject: Move cleanup code to a separate function and export it. Export also X-Git-Tag: php-7.2.0alpha1~620^2~135 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7e9a6f72024e99ab3e85205d208225eda4801d2b;p=php Move cleanup code to a separate function and export it. Export also other functions that can be of use for plugins --- diff --git a/ext/mysqlnd/mysqlnd_connection.c b/ext/mysqlnd/mysqlnd_connection.c index 2cefe755d8..6f350cfd79 100644 --- a/ext/mysqlnd/mysqlnd_connection.c +++ b/ext/mysqlnd/mysqlnd_connection.c @@ -40,7 +40,7 @@ PHPAPI const char * const mysqlnd_server_gone = "MySQL server has gone away"; PHPAPI const char * const mysqlnd_out_of_sync = "Commands out of sync; you can't run this command now"; PHPAPI const char * const mysqlnd_out_of_memory = "Out of memory"; -PHPAPI MYSQLND_STATS *mysqlnd_global_stats = NULL; +PHPAPI MYSQLND_STATS * mysqlnd_global_stats = NULL; /* {{{ mysqlnd_upsert_status::reset */ @@ -152,8 +152,8 @@ MYSQLND_CLASS_METHODS_END; /* {{{ mysqlnd_error_info_init */ -enum_func_status -mysqlnd_error_info_init(MYSQLND_ERROR_INFO * const info, zend_bool persistent) +PHPAPI enum_func_status +mysqlnd_error_info_init(MYSQLND_ERROR_INFO * const info, const zend_bool persistent) { DBG_ENTER("mysqlnd_error_info_init"); info->m = mysqlnd_error_info_get_methods(); @@ -163,12 +163,28 @@ mysqlnd_error_info_init(MYSQLND_ERROR_INFO * const info, zend_bool persistent) if (info->error_list) { zend_llist_init(info->error_list, sizeof(MYSQLND_ERROR_LIST_ELEMENT), (llist_dtor_func_t) mysqlnd_error_list_pdtor, persistent); } - + info->persistent = persistent; DBG_RETURN(info->error_list? PASS:FAIL); } /* }}} */ +/* {{{ mysqlnd_error_info_free_contents */ +PHPAPI void +mysqlnd_error_info_free_contents(MYSQLND_ERROR_INFO * const info) +{ + DBG_ENTER("mysqlnd_error_info_free_contents"); + info->m->reset(info); + if (info->error_list) { + mnd_pefree(info->error_list, info->persistent); + info->error_list = NULL; + } + + DBG_VOID_RETURN; +} +/* }}} */ + + /* {{{ mysqlnd_connection_state::get */ @@ -200,10 +216,8 @@ MYSQLND_CLASS_METHODS_START(mysqlnd_connection_state) MYSQLND_CLASS_METHODS_END; - - /* {{{ mysqlnd_upsert_status_init */ -void +PHPAPI void mysqlnd_connection_state_init(struct st_mysqlnd_connection_state * const state) { DBG_ENTER("mysqlnd_error_info_init"); @@ -214,6 +228,7 @@ mysqlnd_connection_state_init(struct st_mysqlnd_connection_state * const state) /* }}} */ + /* {{{ mysqlnd_conn_data::free_options */ static void MYSQLND_METHOD(mysqlnd_conn_data, free_options)(MYSQLND_CONN_DATA * conn) @@ -318,11 +333,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, free_contents)(MYSQLND_CONN_DATA * conn) mnd_pefree(conn->last_message.s, pers); conn->last_message.s = NULL; } - if (conn->error_info->error_list) { - zend_llist_clean(conn->error_info->error_list); - mnd_pefree(conn->error_info->error_list, pers); - conn->error_info->error_list = NULL; - } + conn->charset = NULL; conn->greet_charset = NULL; @@ -341,6 +352,11 @@ MYSQLND_METHOD_PRIVATE(mysqlnd_conn_data, dtor)(MYSQLND_CONN_DATA * conn) conn->m->free_contents(conn); conn->m->free_options(conn); + if (conn->error_info) { + mysqlnd_error_info_free_contents(conn->error_info); + conn->error_info = NULL; + } + if (conn->protocol_frame_codec) { mysqlnd_pfc_free(conn->protocol_frame_codec, conn->stats, conn->error_info); conn->protocol_frame_codec = NULL; diff --git a/ext/mysqlnd/mysqlnd_connection.h b/ext/mysqlnd/mysqlnd_connection.h index cdffe594d9..0668d09d92 100644 --- a/ext/mysqlnd/mysqlnd_connection.h +++ b/ext/mysqlnd/mysqlnd_connection.h @@ -67,12 +67,13 @@ void mysqlnd_upsert_status_init(MYSQLND_UPSERT_STATUS * const upsert_status); } -enum_func_status mysqlnd_error_info_init(MYSQLND_ERROR_INFO * const info, zend_bool persistent); +PHPAPI enum_func_status mysqlnd_error_info_init(MYSQLND_ERROR_INFO * const info, const zend_bool persistent); +PHPAPI void mysqlnd_error_info_free_contents(MYSQLND_ERROR_INFO * const info); #define GET_CONNECTION_STATE(state_struct) (state_struct)->m->get((state_struct)) #define SET_CONNECTION_STATE(state_struct, s) (state_struct)->m->set((state_struct), (s)) -void mysqlnd_connection_state_init(struct st_mysqlnd_connection_state * const state); +PHPAPI void mysqlnd_connection_state_init(struct st_mysqlnd_connection_state * const state); #endif /* MYSQLND_CONNECTION_H */ diff --git a/ext/mysqlnd/mysqlnd_structs.h b/ext/mysqlnd/mysqlnd_structs.h index 1c213d2a61..cc5e2b7ac4 100644 --- a/ext/mysqlnd/mysqlnd_structs.h +++ b/ext/mysqlnd/mysqlnd_structs.h @@ -157,6 +157,7 @@ struct st_mysqlnd_error_info unsigned int error_no; zend_llist * error_list; + zend_bool persistent; MYSQLND_CLASS_METHODS_TYPE(mysqlnd_error_info) *m; };