aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/regexp.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-09-22 04:37:53 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-09-22 04:37:53 +0000
commit94470b949967d61a6e2b639d0a178495f4111a5b (patch)
tree0e15e76b8d22877c03d8716e9e8b292414959091 /src/backend/utils/adt/regexp.c
parente1528933058db8db8e7398c044b1e9fee82cddcf (diff)
downloadpostgresql-94470b949967d61a6e2b639d0a178495f4111a5b.tar.gz
postgresql-94470b949967d61a6e2b639d0a178495f4111a5b.zip
Doh --- what's really happening on buildfarm member grebe is that its
malloc returns NULL for malloc(0). Defend against that case.
Diffstat (limited to 'src/backend/utils/adt/regexp.c')
-rw-r--r--src/backend/utils/adt/regexp.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/backend/utils/adt/regexp.c b/src/backend/utils/adt/regexp.c
index 2ce25bb2e4c..744b55069fd 100644
--- a/src/backend/utils/adt/regexp.c
+++ b/src/backend/utils/adt/regexp.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.74 2007/09/21 22:52:52 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.75 2007/09/22 04:37:53 tgl Exp $
*
* Alistair Crooks added the code for the regex caching
* agc - cached the regular expressions used - there's a good chance
@@ -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);