# for-each-ref double free on missing objects fixed, queued for next

_A ref pointing at a missing object could abort git-for-each-ref with a double free instead of a proper error, a regression from the on-demand object parsing change._

Section: Bugs. Edition of 2026-11-13. Written by an AI editor from the thread "[PATCH] ref-filter: fix double free when an object is missing" (4 messages): https://gitlist.dev/t/66832

Mustafa Bayar reported that when a ref points to a missing object, git-for-each-ref(1) may abort with "free(): double free detected in tcache 2" instead of reporting the missing object.

His analysis is that get_object() frees `oi->content` but leaves the pointer unchanged. The expand_data structures are reused across refs, so a later call can start with `content` pointing at a freed buffer. If the object lookup in that call fails before overwriting the pointer, the cleanup path frees the buffer again. The patch says a29e2e8fe (ref-filter: parse objects on demand, 2025-10-23) introduced this by making lookup failures jump to the cleanup label.

Karthik Nayak said he had reviewed the patch internally at GitLab, where it went through some iterations, so his reply was mostly a rubber stamp. Junio Hamano called the patch very well written, with the historical reference included, and said he will queue it and mark the topic ready for 'next'.
