]> git.neil.brown.name Git - git.git/commitdiff
reflog-walk: don't free reflogs added to cache
authorJeff King <peff@peff.net>
Fri, 7 Jul 2017 08:41:49 +0000 (04:41 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jul 2017 16:00:31 +0000 (09:00 -0700)
The add_reflog_for_walk() function keeps a cache mapping
refnames to their reflog contents. We use a cached reflog
entry if available, and otherwise allocate and store a new
one.

Since 5026b47175 (add_reflog_for_walk: avoid memory leak,
2017-05-04), when we hit an error parsing a date-based
reflog spec, we free the reflog memory but leave the cache
entry pointing to the now-freed memory.

We can fix this by just leaving the memory intact once it
has made it into the cache. This may leave an unused entry
in the cache, but that's OK. And it means we also catch a
similar situation: we may not have allocated at all in this
invocation, but simply be pointing to a cached entry from a
previous invocation (which is relying on that entry being
present).

The new test in t1411 exercises this case and fails when run
with --valgrind or ASan.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reflog-walk.c
t/t1411-reflog-show.sh

index aec718beba8ae58860759f311a5f8b41c2b78010..2a43537326208343b6dea87b0136d782cd802b76 100644 (file)
@@ -215,10 +215,6 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
        if (recno < 0) {
                commit_reflog->recno = get_reflog_recno_by_time(reflogs, timestamp);
                if (commit_reflog->recno < 0) {
-                       if (reflogs) {
-                               free(reflogs->ref);
-                               free(reflogs);
-                       }
                        free(commit_reflog);
                        return -1;
                }
index ae96eeb66a0fd9d73a5805cd01f32dac857bd483..b9cb76654bd6cf0b7a910ec4c935c38a5f3bf9bc 100755 (executable)
@@ -177,4 +177,8 @@ test_expect_success 'showing multiple reflogs works' '
        git log -g HEAD HEAD >actual
 '
 
+test_expect_success 'showing multiple reflogs with an old date' '
+       git log -g HEAD@{1979-01-01} HEAD >actual
+'
+
 test_done