Skip to content

Commit 1d84a58

Browse files
committed
libmagic: Move the allocation on the stack
1 parent 3d1e7d3 commit 1d84a58

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ext/fileinfo/libmagic/softmagic.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,12 @@ check_fmt(struct magic_set *ms, const char *fmt)
479479
pcre_cache_entry *pce;
480480
int rv = -1;
481481
zend_string *pattern;
482+
ALLOCA_FLAG(use_heap)
482483

483484
if (strchr(fmt, '%') == NULL)
484485
return 0;
485486

486-
pattern = zend_string_init("~%[-0-9\\.]*s~", sizeof("~%[-0-9\\.]*s~") - 1, 0);
487+
ZSTR_ALLOCA_INIT(pattern, "~%[-0-9\\.]*s~", sizeof("~%[-0-9\\.]*s~") - 1, use_heap);
487488
if ((pce = pcre_get_compiled_regex_cache_ex(pattern, 0)) == NULL) {
488489
rv = -1;
489490
} else {
@@ -494,7 +495,7 @@ check_fmt(struct magic_set *ms, const char *fmt)
494495
php_pcre_free_match_data(match_data);
495496
}
496497
}
497-
zend_string_release(pattern);
498+
ZSTR_ALLOCA_FREE(pattern, use_heap);
498499
return rv;
499500
}
500501

0 commit comments

Comments
 (0)