From 9d04d41eec47740da9ec913649c94d62e23956af Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 29 Dec 2024 12:11:36 +0100 Subject: [PATCH] Fix some emalloc() size mistakes 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. --- ext/dom/xpath_callbacks.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/dom/xpath_callbacks.c b/ext/dom/xpath_callbacks.c index cd2ecf4335d..00b5ccb5911 100644 --- a/ext/dom/xpath_callbacks.c +++ b/ext/dom/xpath_callbacks.c @@ -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); @@ -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); @@ -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; @@ -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); } @@ -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;