Skip to content

Commit 9d04d41

Browse files
committed
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.
1 parent 2161959 commit 9d04d41

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

ext/dom/xpath_callbacks.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static zend_result php_dom_xpath_callback_ns_update_method_handler(
192192
if (callable_ht) {
193193
zend_string *key;
194194
ZEND_HASH_FOREACH_STR_KEY_VAL(callable_ht, key, entry) {
195-
zend_fcall_info_cache* fcc = emalloc(sizeof(zend_fcall_info));
195+
zend_fcall_info_cache* fcc = emalloc(sizeof(*fcc));
196196
char *error;
197197
if (!zend_is_callable_ex(entry, NULL, 0, NULL, fcc, &error)) {
198198
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(
235235
zend_argument_value_error(1, "must be a valid callback name");
236236
return FAILURE;
237237
}
238-
zend_fcall_info_cache* fcc = emalloc(sizeof(zend_fcall_info));
238+
zend_fcall_info_cache* fcc = emalloc(sizeof(*fcc));
239239
char *error;
240240
zval tmp;
241241
ZVAL_STR(&tmp, name);
@@ -263,7 +263,7 @@ static php_dom_xpath_callback_ns *php_dom_xpath_callbacks_ensure_ns(php_dom_xpat
263263
{
264264
if (ns == NULL) {
265265
if (!registry->php_ns) {
266-
registry->php_ns = emalloc(sizeof(php_dom_xpath_callback_ns));
266+
registry->php_ns = emalloc(sizeof(*registry->php_ns));
267267
php_dom_xpath_callback_ns_ctor(registry->php_ns);
268268
}
269269
return registry->php_ns;
@@ -274,7 +274,7 @@ static php_dom_xpath_callback_ns *php_dom_xpath_callbacks_ensure_ns(php_dom_xpat
274274
}
275275
php_dom_xpath_callback_ns *namespace = zend_hash_find_ptr(registry->namespaces, ns);
276276
if (namespace == NULL) {
277-
namespace = emalloc(sizeof(php_dom_xpath_callback_ns));
277+
namespace = emalloc(sizeof(*namespace));
278278
php_dom_xpath_callback_ns_ctor(namespace);
279279
zend_hash_add_new_ptr(registry->namespaces, ns, namespace);
280280
}
@@ -295,7 +295,7 @@ PHP_DOM_EXPORT zend_result php_dom_xpath_callbacks_update_single_method_handler(
295295
}
296296

297297
php_dom_xpath_callback_ns *namespace = php_dom_xpath_callbacks_ensure_ns(registry, ns);
298-
zend_fcall_info_cache* allocated_fcc = emalloc(sizeof(zend_fcall_info));
298+
zend_fcall_info_cache* allocated_fcc = emalloc(sizeof(*allocated_fcc));
299299
zend_fcc_dup(allocated_fcc, fcc);
300300

301301
zval registered_value;

0 commit comments

Comments
 (0)