From: Florian Forster Date: Sat, 8 Nov 2008 08:46:29 +0000 (+0100) Subject: filter_pcre: Handle out of memory situations more gracefully. X-Git-Tag: collectd-4.6.0~161 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e1dfb87264e7c3f421c237804aea2952213dc2a8;p=collectd.git filter_pcre: Handle out of memory situations more gracefully. --- diff --git a/src/filter_pcre.c b/src/filter_pcre.c index 7b223e7c..3b1afbf5 100644 --- a/src/filter_pcre.c +++ b/src/filter_pcre.c @@ -153,13 +153,16 @@ static int c_pcre_subst (c_pcre_t *re, char *string, size_t strlen, static regex_t *regex_new (void) { regex_t *re; + regex_t *temp; - ++regexes_num; - regexes = (regex_t *)realloc (regexes, regexes_num * sizeof (*regexes)); - if (NULL == regexes) { + temp = (regex_t *) realloc (regexes, (regexes_num + 1) + * sizeof (*regexes)); + if (NULL == temp) { log_err ("Out of memory."); - exit (5); + return NULL; } + regexes = temp; + regexes_num++; re = regexes + (regexes_num - 1); @@ -360,6 +363,8 @@ static int c_pcre_config_regex (oconfig_item_t *ci) } re = regex_new (); + if (NULL == re) + return -1; for (i = 0; i < ci->children_num; ++i) { oconfig_item_t *c = ci->children + i;