attr.c: plug small leak in parse_attr_line()
If any error is noticed after the match_attr structure is allocated, we shouldn't just return NULL from this function. Add a fail_return label that frees the allocated structure and returns NULL, and consistently jump there when we want to return NULL after cleaning up. Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
12
attr.c
12
attr.c
@ -223,7 +223,7 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
|
|||||||
if (!macro_ok) {
|
if (!macro_ok) {
|
||||||
fprintf(stderr, "%s not allowed: %s:%d\n",
|
fprintf(stderr, "%s not allowed: %s:%d\n",
|
||||||
name, src, lineno);
|
name, src, lineno);
|
||||||
return NULL;
|
goto fail_return;
|
||||||
}
|
}
|
||||||
is_macro = 1;
|
is_macro = 1;
|
||||||
name += strlen(ATTRIBUTE_MACRO_PREFIX);
|
name += strlen(ATTRIBUTE_MACRO_PREFIX);
|
||||||
@ -233,7 +233,7 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%.*s is not a valid attribute name: %s:%d\n",
|
"%.*s is not a valid attribute name: %s:%d\n",
|
||||||
namelen, name, src, lineno);
|
namelen, name, src, lineno);
|
||||||
return NULL;
|
goto fail_return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -246,7 +246,7 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
|
|||||||
for (cp = states, num_attr = 0; *cp; num_attr++) {
|
for (cp = states, num_attr = 0; *cp; num_attr++) {
|
||||||
cp = parse_attr(src, lineno, cp, NULL);
|
cp = parse_attr(src, lineno, cp, NULL);
|
||||||
if (!cp)
|
if (!cp)
|
||||||
return NULL;
|
goto fail_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = xcalloc(1,
|
res = xcalloc(1,
|
||||||
@ -267,7 +267,7 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
|
|||||||
if (res->u.pat.flags & EXC_FLAG_NEGATIVE) {
|
if (res->u.pat.flags & EXC_FLAG_NEGATIVE) {
|
||||||
warning(_("Negative patterns are ignored in git attributes\n"
|
warning(_("Negative patterns are ignored in git attributes\n"
|
||||||
"Use '\\!' for literal leading exclamation."));
|
"Use '\\!' for literal leading exclamation."));
|
||||||
return NULL;
|
goto fail_return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res->is_macro = is_macro;
|
res->is_macro = is_macro;
|
||||||
@ -283,6 +283,10 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
fail_return:
|
||||||
|
free(res);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user