core: Make destructors receive the 'struct cu' their object may have been allocated from
The default, most simple way of freeing memory associated with tags is
to just call free(), but the DWARF loader is a bit more involved in
which it needs extra info to keep its large data structures around for
further processing after loading.
This way we need to provide a way for the DWARF loader to find the real
pointer to release.
So far it was just freeing the tag, which ended up leaking the
tag->priv part, i.e. the associated 'struct dwarf_tag', which wasn't
that much of a problem as the bulk of freeing takes place at tool exit,
but since we want to avoid two allocations and get the 'struct
dwarf_tag' out of pointer arithmetic from the 'struct tag' pointer
associated with it in a single allocation, we have to catch all free()
calls with a 'struct cu' specific tag destructor so that we do that
pointer arithmetic and find the right pointer to feed free().
That or just do nothing when we use obstacks, as in the BTF encoder
case.
So this is all for consistency and correctness, it _shouldn't_ affect
the most critical use case which is BTF encoding, where no such use of
destructors take place.
In the process of getting the codebase more correct we are indeed
catching cases where we, in error paths, were calling free() on obstack
allocated memory, which, again, is a corner case, but lets plug all
these to avoid surprises, that, we know, appear from time to time.
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
7 files changed