From: Junio C Hamano Date: Wed, 30 May 2018 12:51:28 +0000 (+0900) Subject: Merge branch 'ma/regex-no-regfree-after-comp-fail' X-Git-Tag: v2.18.0-rc0~4 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/d89f1248aaf4bb5d1094bc991a50839411935cf6?hp=-c Merge branch 'ma/regex-no-regfree-after-comp-fail' We used to call regfree() after regcomp() failed in some codepaths, which have been corrected. * ma/regex-no-regfree-after-comp-fail: regex: do not call `regfree()` if compilation fails --- d89f1248aaf4bb5d1094bc991a50839411935cf6 diff --combined grep.c index 84f8054a3f,35fccf9aba..45ec7e636c --- a/grep.c +++ b/grep.c @@@ -404,7 -404,7 +404,7 @@@ static void compile_pcre1_regexp(struc die("Couldn't allocate PCRE JIT stack"); pcre_assign_jit_stack(p->pcre1_extra_info, NULL, p->pcre1_jit_stack); } else if (p->pcre1_jit_on != 0) { - die("BUG: The pcre1_jit_on variable should be 0 or 1, not %d", + BUG("The pcre1_jit_on variable should be 0 or 1, not %d", p->pcre1_jit_on); } #endif @@@ -550,7 -550,7 +550,7 @@@ static void compile_pcre2_pattern(struc die("Couldn't allocate PCRE2 match context"); pcre2_jit_stack_assign(p->pcre2_match_context, NULL, p->pcre2_jit_stack); } else if (p->pcre2_jit_on != 0) { - die("BUG: The pcre2_jit_on variable should be 0 or 1, not %d", + BUG("The pcre2_jit_on variable should be 0 or 1, not %d", p->pcre1_jit_on); } } @@@ -636,7 -636,6 +636,6 @@@ static void compile_fixed_regexp(struc if (err) { char errbuf[1024]; regerror(err, &p->regexp, errbuf, sizeof(errbuf)); - regfree(&p->regexp); compile_regexp_failed(p, errbuf); } } @@@ -701,7 -700,6 +700,6 @@@ static void compile_regexp(struct grep_ if (err) { char errbuf[1024]; regerror(err, &p->regexp, errbuf, 1024); - regfree(&p->regexp); compile_regexp_failed(p, errbuf); } } @@@ -917,10 -915,10 +915,10 @@@ static struct grep_expr *prep_header_pa for (p = opt->header_list; p; p = p->next) { if (p->token != GREP_PATTERN_HEAD) - die("BUG: a non-header pattern in grep header list."); + BUG("a non-header pattern in grep header list."); if (p->field < GREP_HEADER_FIELD_MIN || GREP_HEADER_FIELD_MAX <= p->field) - die("BUG: unknown header field %d", p->field); + BUG("unknown header field %d", p->field); compile_regexp(p, opt); } @@@ -933,7 -931,7 +931,7 @@@ h = compile_pattern_atom(&pp); if (!h || pp != p->next) - die("BUG: malformed header expr"); + BUG("malformed header expr"); if (!header_group[p->field]) { header_group[p->field] = h; continue; @@@ -1652,7 -1650,7 +1650,7 @@@ static int fill_textconv_grep(struct us fill_filespec(df, &null_oid, 0, 0100644); break; default: - die("BUG: attempt to textconv something without a path?"); + BUG("attempt to textconv something without a path?"); } /* @@@ -1748,7 -1746,7 +1746,7 @@@ static int grep_source_1(struct grep_op case GREP_BINARY_TEXT: break; default: - die("BUG: unknown binary handling mode"); + BUG("unknown binary handling mode"); } } @@@ -2015,7 -2013,7 +2013,7 @@@ static int grep_source_load_oid(struct enum object_type type; grep_read_lock(); - gs->buf = read_sha1_file(gs->identifier, &type, &gs->size); + gs->buf = read_object_file(gs->identifier, &type, &gs->size); grep_read_unlock(); if (!gs->buf) @@@ -2072,7 -2070,7 +2070,7 @@@ static int grep_source_load(struct grep case GREP_SOURCE_BUF: return gs->buf ? 0 : -1; } - die("BUG: invalid grep_source type to load"); + BUG("invalid grep_source type to load"); } void grep_source_load_driver(struct grep_source *gs)