• Jeff King's avatar
    reflog-walk: don't free reflogs added to cache · 8aae3cf7
    Jeff King authored
    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 5026b471 (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: default avatarJeff King <[email protected]>
    Signed-off-by: default avatarJunio C Hamano <[email protected]>
    8aae3cf7
reflog-walk.c 8.76 KB