Re: Be more careful about updating refs

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Junio C Hamano
Date: Thursday, January 17, 2008 - 6:43 pm

Johannes Sixt <j.sixt@viscovery.net> writes:


I ran strace and found that fast-import retains three windows to
the same data that was opened while the pack was still being
built (i.e. the filename is still tmp_pack_XXXXXX) when it dies:

    {next = 0x6f6d20, base = 0x6f77a0 "PACK", offset = 0, len = 907,
     last_used = 9, inuse_cnt = 0}
    {next = 0x728630, base = 0x6f7160 "PACK", offset = 0, len = 500, 
      last_used = 5, inuse_cnt = 0}
    {next = 0x0, base = 0x6f6d50 "PACK", offset = 0, len = 261, 
      last_used = 1, inuse_cnt = 0}

When it hits end_packfile() to install the built-pack to its
final destination and makes it available to the rest of git,
however, it has this clever code to reuse the still open window.

The object offset asked when it dies is at offset 887.  However,
tmp_pack was written after that last window with length 907 has
been (re)opened, and reusing the window results in reading a
stale data.

The following patch seems to fix the issue for me, but this is
primarily meant for discussion, as I do not quite understand why
the same issue does not manifest itself when NO_MMAP is not
used.

diff --git a/fast-import.c b/fast-import.c
index 3609c24..bd0ddb1 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -926,7 +926,13 @@ static void end_packfile(void)
 		new_p = add_packed_git(idx_name, strlen(idx_name), 1);
 		if (!new_p)
 			die("core git rejected index %s", idx_name);
-		new_p->windows = old_p->windows;
+		while (old_p->windows) {
+			struct pack_window *w = old_p->windows;
+			munmap(w->base, w->len);
+			old_p->windows = w->next;
+			free(w);
+		}
+		new_p->windows = NULL;
 		all_packs[pack_id] = new_p;
 		install_packed_git(new_p);
 
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Be more careful about updating refs, Linus Torvalds, (Tue Jan 15, 4:50 pm)
Re: Be more careful about updating refs, Linus Torvalds, (Tue Jan 15, 5:02 pm)
Re: Be more careful about updating refs, Junio C Hamano, (Tue Jan 15, 5:29 pm)
Re: Be more careful about updating refs, Linus Torvalds, (Tue Jan 15, 5:42 pm)
Re: Be more careful about updating refs, Junio C Hamano, (Tue Jan 15, 6:11 pm)
Re: Be more careful about updating refs, Junio C Hamano, (Wed Jan 16, 12:52 pm)
Re: Be more careful about updating refs, Charles Bailey, (Thu Jan 17, 2:15 am)
Re: Be more careful about updating refs, Johannes Sixt, (Thu Jan 17, 3:52 am)
Re: Be more careful about updating refs, Charles Bailey, (Thu Jan 17, 3:56 am)
Re: Be more careful about updating refs, Charles Bailey, (Thu Jan 17, 4:01 am)
Re: Be more careful about updating refs, Johannes Sixt, (Thu Jan 17, 5:41 am)
Re: Be more careful about updating refs, Johannes Schindelin, (Thu Jan 17, 5:58 am)
Re: Be more careful about updating refs, Charles Bailey, (Thu Jan 17, 6:07 am)
Re: Be more careful about updating refs, Junio C Hamano, (Thu Jan 17, 6:43 pm)
Re: Be more careful about updating refs, Junio C Hamano, (Thu Jan 17, 7:01 pm)
Re: Be more careful about updating refs, Shawn O. Pearce, (Thu Jan 17, 7:13 pm)
Re: Be more careful about updating refs, Junio C Hamano, (Thu Jan 17, 7:25 pm)
Re: Be more careful about updating refs, Shawn O. Pearce, (Thu Jan 17, 7:30 pm)
Re: Be more careful about updating refs, Shawn O. Pearce, (Thu Jan 17, 7:33 pm)
Re: Be more careful about updating refs, Shawn O. Pearce, (Thu Jan 17, 7:58 pm)
Re: Be more careful about updating refs, Shawn O. Pearce, (Thu Jan 17, 8:18 pm)
Re: Be more careful about updating refs, Shawn O. Pearce, (Thu Jan 17, 8:22 pm)
Re: Be more careful about updating refs, Sam Vilain, (Wed Jan 23, 3:53 pm)