summary refs log tree commit
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-06-21 11:24:09 -0700
committerJunio C Hamano <gitster@pobox.com>2019-06-21 11:24:09 -0700
commit34032c4f8fe90aa020f7d85c556312b3d8902f6e (patch)
tree1e3793a41827e50e9d94d4f78408bd2b7d5dbaf3
parent8867aa855e0c5cc7bc80589783295379ae63d175 (diff)
parent7140600e2e78f202594ebca09e3176b6fcac1625 (diff)
The filter_data used in the list-objects-filter (which manages a
lazily sparse clone repository) did not use the dynamic array API
correctly---'nr' is supposed to point at one past the last element
of the array in use.  This has been corrected.

* md/list-objects-filter-memfix:
  list-objects-filter: correct usage of ALLOC_GROW
-rw-r--r--list-objects-filter.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 53f90442c5..36e1f774bc 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -356,13 +356,13 @@ static enum list_objects_filter_result filter_sparse(
                                             filename, &dtype, &filter_data->el,
                                             r->index);
                 if (val < 0)
-                        val = filter_data->array_frame[filter_data->nr].defval;
+                        val = filter_data->array_frame[filter_data->nr - 1].defval;
 
                 ALLOC_GROW(filter_data->array_frame, filter_data->nr + 1,
                            filter_data->alloc);
-                filter_data->nr++;
                 filter_data->array_frame[filter_data->nr].defval = val;
                 filter_data->array_frame[filter_data->nr].child_prov_omit = 0;
+                filter_data->nr++;
 
                 /*
                  * A directory with this tree OID may appear in multiple
@@ -387,16 +387,15 @@ static enum list_objects_filter_result filter_sparse(
 
         case LOFS_END_TREE:
                 assert(obj->type == OBJ_TREE);
-                assert(filter_data->nr > 0);
+                assert(filter_data->nr > 1);
 
-                frame = &filter_data->array_frame[filter_data->nr];
-                filter_data->nr--;
+                frame = &filter_data->array_frame[--filter_data->nr];
 
                 /*
                  * Tell our parent directory if any of our children were
                  * provisionally omitted.
                  */
-                filter_data->array_frame[filter_data->nr].child_prov_omit |=
+                filter_data->array_frame[filter_data->nr - 1].child_prov_omit |=
                         frame->child_prov_omit;
 
                 /*
@@ -412,7 +411,7 @@ static enum list_objects_filter_result filter_sparse(
                 assert(obj->type == OBJ_BLOB);
                 assert((obj->flags & SEEN) == 0);
 
-                frame = &filter_data->array_frame[filter_data->nr];
+                frame = &filter_data->array_frame[filter_data->nr - 1];
 
                 dtype = DT_REG;
                 val = is_excluded_from_list(pathname, strlen(pathname),
@@ -453,7 +452,7 @@ static enum list_objects_filter_result filter_sparse(
 static void filter_sparse_free(void *filter_data)
 {
         struct filter_sparse_data *d = filter_data;
-        /* TODO free contents of 'd' */
+        free(d->array_frame);
         free(d);
 }
 
@@ -472,6 +471,7 @@ static void *filter_sparse_oid__init(
         ALLOC_GROW(d->array_frame, d->nr + 1, d->alloc);
         d->array_frame[d->nr].defval = 0; /* default to include */
         d->array_frame[d->nr].child_prov_omit = 0;
+        d->nr++;
 
         *filter_fn = filter_sparse;
         *filter_free_fn = filter_sparse_free;