Skip to content

Commit

Permalink
Fix some emalloc() size mistakes
Browse files Browse the repository at this point in the history
Fortunately, these only allocate too much memory and not too little.
Also just change it to `sizeof(*var)` everywhere to avoid this mistake
in the future.
  • Loading branch information
nielsdos committed Dec 29, 2024
1 parent 2161959 commit 9d04d41
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ext/dom/xpath_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ static zend_result php_dom_xpath_callback_ns_update_method_handler(
if (callable_ht) {
zend_string *key;
ZEND_HASH_FOREACH_STR_KEY_VAL(callable_ht, key, entry) {
zend_fcall_info_cache* fcc = emalloc(sizeof(zend_fcall_info));
zend_fcall_info_cache* fcc = emalloc(sizeof(*fcc));
char *error;
if (!zend_is_callable_ex(entry, NULL, 0, NULL, fcc, &error)) {
zend_argument_type_error(1, "must be an array with valid callbacks as values, %s", error);
Expand Down Expand Up @@ -235,7 +235,7 @@ static zend_result php_dom_xpath_callback_ns_update_method_handler(
zend_argument_value_error(1, "must be a valid callback name");
return FAILURE;
}
zend_fcall_info_cache* fcc = emalloc(sizeof(zend_fcall_info));
zend_fcall_info_cache* fcc = emalloc(sizeof(*fcc));
char *error;
zval tmp;
ZVAL_STR(&tmp, name);
Expand Down Expand Up @@ -263,7 +263,7 @@ static php_dom_xpath_callback_ns *php_dom_xpath_callbacks_ensure_ns(php_dom_xpat
{
if (ns == NULL) {
if (!registry->php_ns) {
registry->php_ns = emalloc(sizeof(php_dom_xpath_callback_ns));
registry->php_ns = emalloc(sizeof(*registry->php_ns));
php_dom_xpath_callback_ns_ctor(registry->php_ns);
}
return registry->php_ns;
Expand All @@ -274,7 +274,7 @@ static php_dom_xpath_callback_ns *php_dom_xpath_callbacks_ensure_ns(php_dom_xpat
}
php_dom_xpath_callback_ns *namespace = zend_hash_find_ptr(registry->namespaces, ns);
if (namespace == NULL) {
namespace = emalloc(sizeof(php_dom_xpath_callback_ns));
namespace = emalloc(sizeof(*namespace));
php_dom_xpath_callback_ns_ctor(namespace);
zend_hash_add_new_ptr(registry->namespaces, ns, namespace);
}
Expand All @@ -295,7 +295,7 @@ PHP_DOM_EXPORT zend_result php_dom_xpath_callbacks_update_single_method_handler(
}

php_dom_xpath_callback_ns *namespace = php_dom_xpath_callbacks_ensure_ns(registry, ns);
zend_fcall_info_cache* allocated_fcc = emalloc(sizeof(zend_fcall_info));
zend_fcall_info_cache* allocated_fcc = emalloc(sizeof(*allocated_fcc));
zend_fcc_dup(allocated_fcc, fcc);

zval registered_value;
Expand Down

0 comments on commit 9d04d41

Please sign in to comment.