]> granicus.if.org Git - php/commitdiff
libmagic: Move the allocation on the stack
authorAnatol Belski <ab@php.net>
Wed, 2 Sep 2020 14:58:44 +0000 (16:58 +0200)
committerAnatol Belski <ab@php.net>
Wed, 2 Sep 2020 15:35:51 +0000 (17:35 +0200)
ext/fileinfo/libmagic/softmagic.c

index a99e60c5634ca80d73be736ce7576bbc300a75a4..e71e6cf8324a1539dc69a79b2982cc1f4e2ae9fa 100644 (file)
@@ -479,11 +479,12 @@ check_fmt(struct magic_set *ms, const char *fmt)
        pcre_cache_entry *pce;
        int rv = -1;
        zend_string *pattern;
+       ALLOCA_FLAG(use_heap)
 
        if (strchr(fmt, '%') == NULL)
                return 0;
 
-       pattern = zend_string_init("~%[-0-9\\.]*s~", sizeof("~%[-0-9\\.]*s~") - 1, 0);
+       ZSTR_ALLOCA_INIT(pattern, "~%[-0-9\\.]*s~", sizeof("~%[-0-9\\.]*s~") - 1, use_heap);
        if ((pce = pcre_get_compiled_regex_cache_ex(pattern, 0)) == NULL) {
                rv = -1;
        } else {
@@ -494,7 +495,7 @@ check_fmt(struct magic_set *ms, const char *fmt)
                        php_pcre_free_match_data(match_data);
                }
        }
-       zend_string_release(pattern);
+       ZSTR_ALLOCA_FREE(pattern, use_heap);
        return rv;
 }