Re: [PATCH 1/4] diff.c: call regfree to free memory allocated by regcomp when necessary
- From
Jeff King <peff@peff.net>
- Date
- Sep 9, 2010, 19:15 UTC
- Message-ID
- <20100909191557.GB32508@sigill.intra.peff.net>
- In-Reply-To
- <rRj7JpFIk_D_n7-wGkkucFJE0330IabsqMoSzalswHpjT-Z1HCuOFaIgMsaPgIuQSp0KUMW97Wo@cipher.nrlssc.navy.mil>
On Thu, Sep 09, 2010 at 02:02:45PM -0500, Brandon Casey wrote:
Show 9 quoted lines
> @@ -919,7 +919,10 @@ static void free_diff_words_data(struct emit_callback *ecbdata)
> free (ecbdata->diff_words->minus.orig);
> free (ecbdata->diff_words->plus.text.ptr);
> free (ecbdata->diff_words->plus.orig);
> - free(ecbdata->diff_words->word_regex);
> + if (ecbdata->diff_words->word_regex) {
> + regfree(ecbdata->diff_words->word_regex);
> + free(ecbdata->diff_words->word_regex);
> + }Makes sense, and closes a leak. But I wonder why word_regex is a pointer to malloc'd memory at all? Couldn't it just be an actual regex_t inside the diff_words struct, and we regcomp and regfree it?
I guess maybe having it be NULL is useful. You could check diff_words->o->word_regex, but I suppose that would mean carrying an extra variable around through the callchain.
-Peff