提交 46be8231 编写于 作者: J Jeff King 提交者: Junio C Hamano

object_array: add a "clear" function

There's currently no easy way to free the memory associated
with an object_array (and in most cases, we simply leak the
memory in a rev_info's pending array). Let's provide a
helper to make this easier to handle.

We can make use of it in list-objects.c, which does the same
thing by hand (but fails to free the "name" field of each
entry, potentially leaking memory).
Signed-off-by: NJeff King <peff@peff.net>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 68f49235
......@@ -228,11 +228,6 @@ void traverse_commit_list(struct rev_info *revs,
die("unknown pending object %s (%s)",
sha1_to_hex(obj->sha1), name);
}
if (revs->pending.nr) {
free(revs->pending.objects);
revs->pending.nr = 0;
revs->pending.alloc = 0;
revs->pending.objects = NULL;
}
object_array_clear(&revs->pending);
strbuf_release(&base);
}
......@@ -383,6 +383,16 @@ void object_array_filter(struct object_array *array,
array->nr = dst;
}
void object_array_clear(struct object_array *array)
{
int i;
for (i = 0; i < array->nr; i++)
object_array_release_entry(&array->objects[i]);
free(array->objects);
array->objects = NULL;
array->nr = array->alloc = 0;
}
/*
* Return true iff array already contains an entry with name.
*/
......
......@@ -133,6 +133,12 @@ void object_array_filter(struct object_array *array,
*/
void object_array_remove_duplicates(struct object_array *array);
/*
* Remove any objects from the array, freeing all used memory; afterwards
* the array is ready to store more objects with add_object_array().
*/
void object_array_clear(struct object_array *array);
void clear_object_flags(unsigned flags);
#endif /* OBJECT_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册