do_for_each_entry(): increment the packed refs cache refcount
This function calls a user-supplied callback function which could do something that causes the packed refs cache to be invalidated. So acquire a reference count on the data structure to prevent our copy from being freed while we are iterating over it. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Jun 20, 2013 at 10:37 UTC
8baf2bb99a22f8265a26d97f706a27e39911f69e
1 file changed
+4
-1
refs.c
+4
-1
@@ -1590,10 +1590,12 @@ void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname)
1590
static int do_for_each_entry(struct ref_cache *refs, const char *base,
1591
each_ref_entry_fn fn, void *cb_data)
1592
{
1593
- struct ref_dir *packed_dir = get_packed_refs(refs);
1593
+ struct packed_ref_cache *packed_ref_cache = get_packed_ref_cache(refs);
1594
+ struct ref_dir *packed_dir = get_packed_ref_dir(packed_ref_cache);
1595
struct ref_dir *loose_dir = get_loose_refs(refs);
1596
int retval = 0;
1597
1598
+ acquire_packed_ref_cache(packed_ref_cache);
1599
if (base && *base) {
1600
packed_dir = find_containing_dir(packed_dir, base, 0);
1601
loose_dir = find_containing_dir(loose_dir, base, 0);
@@ -1614,6 +1616,7 @@ static int do_for_each_entry(struct ref_cache *refs, const char *base,
1616
loose_dir, 0, fn, cb_data);
1617
}
1618
1619
+ release_packed_ref_cache(packed_ref_cache);
1620
return retval;
1621
}
1622