Doh --- what's really happening on buildfarm member grebe is that its
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 22 Sep 2007 04:37:53 +0000 (04:37 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 22 Sep 2007 04:37:53 +0000 (04:37 +0000)
malloc returns NULL for malloc(0).  Defend against that case.

src/backend/utils/adt/regexp.c

index eb0cbe764354464ba81f582e96f3e071af4df83e..f9263063c72d668cca17c3373bd63aa84ccc79e5 100644 (file)
@@ -195,10 +195,12 @@ RE_compile_and_cache(text *text_re, int cflags)
        }
 
        /*
-        * use malloc/free for the cre_pat field because the storage has to
-        * persist across transactions
+        * We use malloc/free for the cre_pat field because the storage has to
+        * persist across transactions, and because we want to get control back
+        * on out-of-memory.  The Max() is because some malloc implementations
+        * return NULL for malloc(0).
         */
-       re_temp.cre_pat = malloc(text_re_len);
+       re_temp.cre_pat = malloc(Max(text_re_len, 1));
        if (re_temp.cre_pat == NULL)
        {
                pg_regfree(&re_temp.cre_re);