Skip to content

Commit 4f6b83e

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8baf2bb commit 4f6b83e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

refs.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,9 @@ struct packed_ref_cache {
820820
/*
821821
* Iff the packed-refs file associated with this instance is
822822
* currently locked for writing, this points at the associated
823-
* lock (which is owned by somebody else).
823+
* lock (which is owned by somebody else). The referrer count
824+
* is also incremented when the file is locked and decremented
825+
* when it is unlocked.
824826
*/
825827
struct lock_file *lock;
826828
};
@@ -2099,6 +2101,8 @@ int lock_packed_refs(int flags)
20992101
/* Read the current packed-refs while holding the lock: */
21002102
packed_ref_cache = get_packed_ref_cache(&ref_cache);
21012103
packed_ref_cache->lock = &packlock;
2104+
/* Increment the reference count to prevent it from being freed: */
2105+
acquire_packed_ref_cache(packed_ref_cache);
21022106
return 0;
21032107
}
21042108

@@ -2119,6 +2123,7 @@ int commit_packed_refs(void)
21192123
if (commit_lock_file(packed_ref_cache->lock))
21202124
error = -1;
21212125
packed_ref_cache->lock = NULL;
2126+
release_packed_ref_cache(packed_ref_cache);
21222127
return error;
21232128
}
21242129

@@ -2131,6 +2136,7 @@ void rollback_packed_refs(void)
21312136
die("internal error: packed-refs not locked");
21322137
rollback_lock_file(packed_ref_cache->lock);
21332138
packed_ref_cache->lock = NULL;
2139+
release_packed_ref_cache(packed_ref_cache);
21342140
clear_packed_ref_cache(&ref_cache);
21352141
}
21362142

0 commit comments

Comments
 (0)