|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * IDENTIFICATION |
11 | | - * $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.74 2007/09/21 22:52:52 tgl Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.75 2007/09/22 04:37:53 tgl Exp $ |
12 | 12 | * |
13 | 13 | *Alistair Crooks added the code for the regex caching |
14 | 14 | *agc - cached the regular expressions used - there's a good chance |
@@ -195,10 +195,12 @@ RE_compile_and_cache(text *text_re, int cflags) |
195 | 195 | } |
196 | 196 |
|
197 | 197 | /* |
198 | | - * use malloc/free for the cre_pat field because the storage has to |
199 | | - * persist across transactions |
| 198 | + * We use malloc/free for the cre_pat field because the storage has to |
| 199 | + * persist across transactions, and because we want to get control back |
| 200 | + * on out-of-memory. The Max() is because some malloc implementations |
| 201 | + * return NULL for malloc(0). |
200 | 202 | */ |
201 | | -re_temp.cre_pat=malloc(text_re_len); |
| 203 | +re_temp.cre_pat=malloc(Max(text_re_len,1)); |
202 | 204 | if (re_temp.cre_pat==NULL) |
203 | 205 | { |
204 | 206 | pg_regfree(&re_temp.cre_re); |
|