From: Tomas Mraz Date: Fri, 11 Mar 2011 16:02:25 +0000 (+0100) Subject: Check malloc return for NULL. X-Git-Tag: cronie1.4.7~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=22bfe8a88e1ea0ac933400dc9cc68a3bf3177f72;p=cronie Check malloc return for NULL. --- diff --git a/anacron/matchrx.c b/anacron/matchrx.c index 905694e..17bec93 100644 --- a/anacron/matchrx.c +++ b/anacron/matchrx.c @@ -48,16 +48,18 @@ match_rx(const char *rx, char *string, int n_sub, /* char **substrings */...) char **substring; regmatch_t *sub_offsets; sub_offsets = malloc(sizeof(regmatch_t) * (n_sub + 1)); + if (sub_offsets == NULL) + return -1; memset(sub_offsets, 0, sizeof(regmatch_t) * (n_sub + 1)); if (regcomp(&crx, rx, REG_EXTENDED)) { free(sub_offsets); - return - 1; + return -1; } r = regexec(&crx, string, n_sub + 1, sub_offsets, 0); if (r != 0 && r != REG_NOMATCH) { free(sub_offsets); - return - 1; + return -1; } regfree(&crx); if (r == REG_NOMATCH) {