Skip to content

Commit d3118c3

Browse files
committed
Try to fix memory leaks
1 parent ae0cb25 commit d3118c3

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

parser/parser.php5.inc.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,34 @@ static void parser_add_str(zval *arr, const char *key, const char *val) {
1818
zval *tmp;
1919
MAKE_STD_ZVAL(tmp);
2020
ZVAL_STRING(tmp, val, 1);
21-
zend_hash_add(Z_ARRVAL_P(arr), key, strlen(key) + 1, (void **)&tmp, sizeof(zval *), NULL);
21+
if (zend_hash_add(Z_ARRVAL_P(arr), key, strlen(key) + 1, (void **)&tmp, sizeof(zval *), NULL) == FAILURE) {
22+
zval_ptr_dtor(&tmp);
23+
}
2224
}
2325

2426
static void parser_add_str_free(zval *arr, const char *key, char *val) {
2527
zval *tmp;
2628
MAKE_STD_ZVAL(tmp);
2729
ZVAL_STRING(tmp, val, 1);
28-
zend_hash_add(Z_ARRVAL_P(arr), key, strlen(key) + 1, (void **)&tmp, sizeof(zval *), NULL);
30+
if (zend_hash_add(Z_ARRVAL_P(arr), key, strlen(key) + 1, (void **)&tmp, sizeof(zval *), NULL) == FAILURE) {
31+
zval_ptr_dtor(&tmp);
32+
}
2933
efree(val);
3034
}
3135

3236
static void parser_add_int(zval *arr, const char *key, int i) {
3337
zval *tmp;
3438
MAKE_STD_ZVAL(tmp);
3539
ZVAL_LONG(tmp, i);
36-
zend_hash_add(Z_ARRVAL_P(arr), key, strlen(key) + 1, (void **)&tmp, sizeof(zval *), NULL);
40+
if (zend_hash_add(Z_ARRVAL_P(arr), key, strlen(key) + 1, (void **)&tmp, sizeof(zval *), NULL) == FAILURE) {
41+
zval_ptr_dtor(&tmp);
42+
}
3743
}
3844

3945
static void parser_add_zval(zval *arr, const char *key, zval *zv) {
40-
zend_hash_add(Z_ARRVAL_P(arr), key, strlen(key) + 1, (void **)&zv, sizeof(zval *), NULL);
46+
if (zend_hash_add(Z_ARRVAL_P(arr), key, strlen(key) + 1, (void **)&zv, sizeof(zval *), NULL) == FAILURE) {
47+
zval_ptr_dtor(&zv);
48+
}
4149
}
4250

4351
static void parser_array_append(zval *arr, zval *zv) {

zephir_parser.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ PHP_FUNCTION(zephir_parse_file)
4747
#endif
4848

4949
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &content, &content_len, &filepath, &filepath_len) == FAILURE) {
50-
return;
50+
RETURN_FALSE;
5151
}
5252

5353
#if PHP_VERSION_ID >= 70000
@@ -63,7 +63,7 @@ PHP_FUNCTION(zephir_parse_file)
6363
}
6464
RETURN_ZVAL(&ret, 1, 1);
6565
#else
66-
RETVAL_ZVAL(ret, 1, 0);
66+
RETVAL_ZVAL(ret, 1, 1);
6767
#endif
6868
}
6969
/* }}} */
@@ -101,7 +101,10 @@ PHP_MINFO_FUNCTION(zephir_parser)
101101
}
102102
/* }}} */
103103

104-
/* {{{ zephir_parser_functions[] */
104+
/* {{{ zephir_parser_functions[]
105+
*
106+
* Every user visible function must have an entry in zephir_parser_functions[].
107+
*/
105108
static const zend_function_entry zephir_parser_functions[] = {
106109
PHP_FE(zephir_parse_file, NULL)
107110
PHP_FE_END
@@ -131,3 +134,12 @@ ZEND_TSRMLS_CACHE_DEFINE();
131134
#endif
132135
ZEND_GET_MODULE(zephir_parser)
133136
#endif
137+
138+
/*
139+
* Local variables:
140+
* tab-width: 4
141+
* c-basic-offset: 4
142+
* End:
143+
* vim600: noet sw=4 ts=4 fdm=marker
144+
* vim<600: noet sw=4 ts=4
145+
*/

0 commit comments

Comments
 (0)