Skip to content

Commit a039383

Browse files
committed
Refactor ibase_free_query(), ibase_free_result()
1 parent a5e5fb5 commit a039383

File tree

2 files changed

+15
-64
lines changed

2 files changed

+15
-64
lines changed

ibase_query.c

Lines changed: 14 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -84,29 +84,18 @@ static void _php_ibase_free_query(ibase_query *ib_query) /* {{{ */
8484
{
8585
IBDEBUG("Freeing query...");
8686

87-
if (ib_query->in_sqlda) {
88-
efree(ib_query->in_sqlda);
89-
}
90-
if (ib_query->out_sqlda) {
91-
efree(ib_query->out_sqlda);
92-
}
93-
if (ib_query->stmt_res != NULL) {
94-
zend_list_delete(ib_query->stmt_res);
95-
ib_query->stmt_res = NULL;
96-
}
97-
if (ib_query->result_res != NULL) {
98-
zend_list_delete(ib_query->result_res);
99-
ib_query->result_res = NULL;
100-
}
101-
if (ib_query->in_array) {
102-
efree(ib_query->in_array);
103-
}
104-
if (ib_query->out_array) {
105-
efree(ib_query->out_array);
106-
}
107-
if (ib_query->query) {
108-
efree(ib_query->query);
109-
}
87+
if(ib_query->in_nullind)efree(ib_query->in_nullind);
88+
if(ib_query->out_nullind)efree(ib_query->out_nullind);
89+
if(ib_query->bind_buf)efree(ib_query->bind_buf);
90+
if(ib_query->in_sqlda)efree(ib_query->in_sqlda); // Note to myself: no need for _php_ibase_free_xsqlda()
91+
if(ib_query->out_sqlda)_php_ibase_free_xsqlda(ib_query->out_sqlda);
92+
if(ib_query->in_array)efree(ib_query->in_array);
93+
if(ib_query->out_array)efree(ib_query->out_array);
94+
if(ib_query->query)efree(ib_query->query);
95+
if(ib_query->ht_aliases)zend_array_destroy(ib_query->ht_aliases);
96+
if(ib_query->ht_ind)zend_array_destroy(ib_query->ht_ind);
97+
98+
efree(ib_query);
11099
}
111100
/* }}} */
112101

@@ -117,7 +106,6 @@ static void php_ibase_free_query_rsrc(zend_resource *rsrc) /* {{{ */
117106
if (ib_query != NULL) {
118107
IBDEBUG("Preparing to free query by dtor...");
119108
_php_ibase_free_query(ib_query);
120-
efree(ib_query);
121109
}
122110
}
123111
/* }}} */
@@ -1756,29 +1744,7 @@ PHP_FUNCTION(ibase_name_result)
17561744
Free the memory used by a result */
17571745
PHP_FUNCTION(ibase_free_result)
17581746
{
1759-
zval *result_arg;
1760-
ibase_result *ib_result;
1761-
1762-
RESET_ERRMSG;
1763-
1764-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &result_arg) == FAILURE) {
1765-
return;
1766-
}
1767-
1768-
ib_result = (ibase_result *)zend_fetch_resource_ex(result_arg, LE_RESULT, le_result);
1769-
1770-
_php_ibase_free_xsqlda(ib_result->out_sqlda);
1771-
efree(ib_result);
1772-
1773-
zend_list_delete(Z_RES_P(result_arg));
1774-
1775-
/*
1776-
* Bugfix of issue #40
1777-
* Reset pointer after freeing to NULL
1778-
*/
1779-
Z_RES_P(result_arg)->ptr = NULL;
1780-
1781-
RETURN_TRUE;
1747+
// ibase_result was removed, nothing to be done here
17821748
}
17831749
/* }}} */
17841750

@@ -1867,23 +1833,7 @@ PHP_FUNCTION(ibase_execute)
18671833
Free memory used by a query */
18681834
PHP_FUNCTION(ibase_free_query)
18691835
{
1870-
zval *query_arg;
1871-
ibase_query *ib_query;
1872-
1873-
RESET_ERRMSG;
1874-
1875-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &query_arg) == FAILURE) {
1876-
return;
1877-
}
1878-
1879-
ib_query = (ibase_query *)zend_fetch_resource_ex(query_arg, LE_QUERY, le_query);
1880-
if (!ib_query) {
1881-
RETURN_FALSE;
1882-
}
1883-
1884-
zend_list_close(Z_RES_P(query_arg));
1885-
zend_list_delete(Z_RES_P(query_arg));
1886-
RETURN_TRUE;
1836+
_php_ibase_free_query_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU);
18871837
}
18881838
/* }}} */
18891839

php_ibase_includes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ static int _php_ibase_get_vars_count(ibase_query *ib_query);
258258
static int _php_ibase_fetch_query_res(zval *from, ibase_query **ib_query);
259259
static int _php_ibase_alloc_ht_aliases(ibase_query *ib_query);
260260
static void _php_ibase_alloc_ht_ind(ibase_query *ib_query);
261+
static void _php_ibase_free_query_impl(INTERNAL_FUNCTION_PARAMETERS);
261262

262263
#ifdef __cplusplus
263264
}

0 commit comments

Comments
 (0)