From: Junio C Hamano <gits...@pobox.com>

One codepath needs to just empty the git_attr_check_elem array in
the git_attr_check structure, without releasing the entire resource.
Introduce a helper to do so and rewrite git_attr_check_clear() using
it.

Signed-off-by: Junio C Hamano <gits...@pobox.com>
Signed-off-by: Stefan Beller <sbel...@google.com>
---
 attr.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/attr.c b/attr.c
index 94476de3d2..1098300e54 100644
--- a/attr.c
+++ b/attr.c
@@ -750,6 +750,14 @@ static int attr_check_is_dynamic(const struct 
git_attr_check *check)
        return (void *)(check->check) != (void *)(check + 1);
 }
 
+static void empty_attr_check_elems(struct git_attr_check *check)
+{
+       if (!attr_check_is_dynamic(check))
+               die("BUG: emptying a statically initialized git_attr_check");
+       check->check_nr = 0;
+       check->finalized = 0;
+}
+
 /*
  * Collect attributes for path into the array pointed to by
  * check_all_attr.  If check is not NULL, only attributes in
@@ -916,12 +924,11 @@ struct git_attr_check_elem *git_attr_check_append(struct 
git_attr_check *check,
 
 void git_attr_check_clear(struct git_attr_check *check)
 {
+       empty_attr_check_elems(check);
        if (!attr_check_is_dynamic(check))
                die("BUG: clearing a statically initialized git_attr_check");
        free(check->check);
-       check->check_nr = 0;
        check->check_alloc = 0;
-       check->finalized = 0;
 }
 
 void git_attr_check_free(struct git_attr_check *check)
-- 
2.10.1.714.ge3da0db

Reply via email to