Skip to content

Commit

Permalink
Clear the delta base cache during fast-import checkpoint
Browse files Browse the repository at this point in the history
Otherwise we may reuse the same memory address for a totally
different "struct packed_git", and a previously cached object from
the prior occupant might be returned when trying to unpack an object
from the new pack.

Found-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Shawn O. Pearce authored and Junio C Hamano committed Feb 10, 2009
1 parent ab2fdb3 commit 3d20c63
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ extern unsigned char* use_pack(struct packed_git *, struct pack_window **, off_t
extern void close_pack_windows(struct packed_git *);
extern void unuse_pack(struct pack_window **);
extern void free_pack_by_name(const char *);
extern void clear_delta_base_cache(void);
extern struct packed_git *add_packed_git(const char *, int, int);
extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t);
extern off_t nth_packed_object_offset(const struct packed_git *, uint32_t);
Expand Down
1 change: 1 addition & 0 deletions fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ static void end_packfile(void)
{
struct packed_git *old_p = pack_data, *new_p;

clear_delta_base_cache();
if (object_count) {
char *idx_name;
int i;
Expand Down
7 changes: 7 additions & 0 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,13 @@ static inline void release_delta_base_cache(struct delta_base_cache_entry *ent)
}
}

void clear_delta_base_cache(void)
{
unsigned long p;
for (p = 0; p < MAX_DELTA_CACHE; p++)
release_delta_base_cache(&delta_base_cache[p]);
}

static void add_delta_base_cache(struct packed_git *p, off_t base_offset,
void *base, unsigned long base_size, enum object_type type)
{
Expand Down

0 comments on commit 3d20c63

Please sign in to comment.