Update contrib/trgm_regexp's memory management.
authorThomas Munro <[email protected]>
Sat, 8 Apr 2023 09:55:28 +0000 (21:55 +1200)
committerThomas Munro <[email protected]>
Sat, 8 Apr 2023 10:09:17 +0000 (22:09 +1200)
While no code change was necessary for this code to keep working, we
don't need to use PG_TRY()/PG_FINALLY() with explicit clean-up while
working with regexes anymore.

Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/CA%2BhUKGK3PGKwcKqzoosamn36YW-fsuTdOPPF1i_rtEO%3DnEYKSg%40mail.gmail.com

contrib/pg_trgm/trgm_regexp.c

index 06cd3db67beeded09ca70df0731ad965b450f381..1d3694606719f3a77e74a413285b3aba4fd78f6a 100644 (file)
@@ -549,22 +549,9 @@ createTrgmNFA(text *text_re, Oid collation,
               REG_ADVANCED | REG_NOSUB, collation);
 #endif
 
-   /*
-    * Since the regexp library allocates its internal data structures with
-    * malloc, we need to use a PG_TRY block to ensure that pg_regfree() gets
-    * done even if there's an error.
-    */
-   PG_TRY();
-   {
-       trg = createTrgmNFAInternal(&regex, graph, rcontext);
-   }
-   PG_FINALLY();
-   {
-       pg_regfree(&regex);
-   }
-   PG_END_TRY();
+   trg = createTrgmNFAInternal(&regex, graph, rcontext);
 
-   /* Clean up all the cruft we created */
+   /* Clean up all the cruft we created (including regex) */
    MemoryContextSwitchTo(oldcontext);
    MemoryContextDelete(tmpcontext);