[augeas-devel] [PATCH 3 of 4] Check for (some) allocation failures
David Lutterkort
dlutter at redhat.com
Fri May 9 16:07:33 UTC 2008
On Fri, 2008-05-09 at 00:50 -0400, James Antill wrote:
> static struct re *make_re_rep(struct re *exp, int min, int max) {
> struct re *re = make_re(ITER);
> - re->exp = exp;
> - re->min = min;
> - re->max = max;
> + if (re) {
> + re->exp = ref(exp);
> + re->min = min;
> + re->max = max;
> + }
> + unref(exp, re); /* don't leak what was passed in on failure */
> return re;
> }
Just for the record: I changed the patch with a slight variant of this:
static struct re *make_re_rep(struct re *exp, int min, int max)
{
struct re *re = make_re(ITER);
if (re) {
re->exp = exp;
re->min = min;
re->max = max;
} else {
re_unref(exp);
}
return re;
}
Same for make_re_binop.
David
More information about the augeas-devel
mailing list