]> granicus.if.org Git - php/commitdiff
MFH (pcre cache flush)
authorAndrei Zmievski <andrei@php.net>
Tue, 24 May 2005 21:12:16 +0000 (21:12 +0000)
committerAndrei Zmievski <andrei@php.net>
Tue, 24 May 2005 21:12:16 +0000 (21:12 +0000)
ext/pcre/php_pcre.c

index 7eba5a639dee63cf2dfd4aa18ee02a7f450766e0..e25be3a3207f3ced0d40467efc85615156976eae 100644 (file)
@@ -152,13 +152,21 @@ PHPAPI pcre* pcre_get_compiled_regex(char *regex, pcre_extra **extra, int *preg_
           back the compiled pattern, otherwise go on and compile it. */
        regex_len = strlen(regex);
        if (zend_hash_find(&PCRE_G(pcre_cache), regex, regex_len+1, (void **)&pce) == SUCCESS) {
+               /*
+                * We use a quick pcre_info() check to see whether cache is corrupted, and if it
+                * is, we flush it and compile the pattern from scratch.
+                */
+               if (pcre_info(pce->re, NULL, NULL) == PCRE_ERROR_BADMAGIC) {
+                       zend_hash_clean(&PCRE_G(pcre_cache));
+               } else {
 #if HAVE_SETLOCALE
-               if (!strcmp(pce->locale, locale)) {
+                       if (!strcmp(pce->locale, locale)) {
 #endif
-                       *extra = pce->extra;
-                       *preg_options = pce->preg_options;
-                       return pce->re;
+                               *extra = pce->extra;
+                               *preg_options = pce->preg_options;
+                               return pce->re;
 #if HAVE_SETLOCALE
+                       }
                }
 #endif
        }