Skip to content

Commit 8aae3cf

Browse files
peffgitster
authored andcommitted
reflog-walk: don't free reflogs added to cache
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 5026b47 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 75afe7a commit 8aae3cf

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

reflog-walk.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,6 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
215215
if (recno < 0) {
216216
commit_reflog->recno = get_reflog_recno_by_time(reflogs, timestamp);
217217
if (commit_reflog->recno < 0) {
218-
if (reflogs) {
219-
free(reflogs->ref);
220-
free(reflogs);
221-
}
222218
free(commit_reflog);
223219
return -1;
224220
}

t/t1411-reflog-show.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,8 @@ test_expect_success 'showing multiple reflogs works' '
177177
git log -g HEAD HEAD >actual
178178
'
179179

180+
test_expect_success 'showing multiple reflogs with an old date' '
181+
git log -g HEAD@{1979-01-01} HEAD >actual
182+
'
183+
180184
test_done

0 commit comments

Comments
 (0)