packed_ref_cache: increment refcount when locked
Increment the packed_ref_cache reference count while it is locked to prevent its being freed. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
8baf2bb99a
commit
4f6b83e370
8
refs.c
8
refs.c
@ -820,7 +820,9 @@ struct packed_ref_cache {
|
|||||||
/*
|
/*
|
||||||
* Iff the packed-refs file associated with this instance is
|
* Iff the packed-refs file associated with this instance is
|
||||||
* currently locked for writing, this points at the associated
|
* currently locked for writing, this points at the associated
|
||||||
* lock (which is owned by somebody else).
|
* lock (which is owned by somebody else). The referrer count
|
||||||
|
* is also incremented when the file is locked and decremented
|
||||||
|
* when it is unlocked.
|
||||||
*/
|
*/
|
||||||
struct lock_file *lock;
|
struct lock_file *lock;
|
||||||
};
|
};
|
||||||
@ -2099,6 +2101,8 @@ int lock_packed_refs(int flags)
|
|||||||
/* Read the current packed-refs while holding the lock: */
|
/* Read the current packed-refs while holding the lock: */
|
||||||
packed_ref_cache = get_packed_ref_cache(&ref_cache);
|
packed_ref_cache = get_packed_ref_cache(&ref_cache);
|
||||||
packed_ref_cache->lock = &packlock;
|
packed_ref_cache->lock = &packlock;
|
||||||
|
/* Increment the reference count to prevent it from being freed: */
|
||||||
|
acquire_packed_ref_cache(packed_ref_cache);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2119,6 +2123,7 @@ int commit_packed_refs(void)
|
|||||||
if (commit_lock_file(packed_ref_cache->lock))
|
if (commit_lock_file(packed_ref_cache->lock))
|
||||||
error = -1;
|
error = -1;
|
||||||
packed_ref_cache->lock = NULL;
|
packed_ref_cache->lock = NULL;
|
||||||
|
release_packed_ref_cache(packed_ref_cache);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2131,6 +2136,7 @@ void rollback_packed_refs(void)
|
|||||||
die("internal error: packed-refs not locked");
|
die("internal error: packed-refs not locked");
|
||||||
rollback_lock_file(packed_ref_cache->lock);
|
rollback_lock_file(packed_ref_cache->lock);
|
||||||
packed_ref_cache->lock = NULL;
|
packed_ref_cache->lock = NULL;
|
||||||
|
release_packed_ref_cache(packed_ref_cache);
|
||||||
clear_packed_ref_cache(&ref_cache);
|
clear_packed_ref_cache(&ref_cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user