summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-07-13 20:27:32 +0200
committerwm4 <wm4@nowhere>2019-09-19 20:37:05 +0200
commit36dd2348a1e118b44fcccd3c664af7c5f960b6bb (patch)
tree548c2f6e78ad319fd1510c459f2fc4af9c8e6123
parent0edccfd820e4812ed52cea85109f80ca13f74e97 (diff)
downloadmpv-36dd2348a1e118b44fcccd3c664af7c5f960b6bb.tar.bz2
mpv-36dd2348a1e118b44fcccd3c664af7c5f960b6bb.tar.xz
ta: destroy/free children in reverse order
This matters when talloc allocations set destructors. Before this commit, destructors were called in the same order as they were added to the parent allocations. Now it happens in reverse order. I think this makes more sense. It's reasonable to assume that an allocation that was added later may depend on any of the previous allocations, so later additions should be destroyed first. (Of course other orders are entirely possible too.) Hopefully this doesn't fix or break anything, but I can't be sure (about either of those). It's risky. (Then why do it?) The destructor of a parent allocation is called before its children. It makes sense and must stay this way, because in most cases, the destructor wants to access the children. This is a reason why I don't really like talloc (it wasn't my idea to use talloc, is my excuse). Quite possible that destructors should be removed from talloc entirely. Actually, this project should probably be rewritten in Rust (or a better language), but that would be even more of a pain; also, I think this is just the right level of suffering and punishment.
-rw-r--r--ta/ta.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/ta/ta.c b/ta/ta.c
index f8966bd020..817ccfd3ab 100644
--- a/ta/ta.c
+++ b/ta/ta.c
@@ -246,8 +246,8 @@ void ta_free_children(void *ptr)
struct ta_ext_header *eh = h ? h->ext : NULL;
if (!eh)
return;
- while (eh->children.next != &eh->children)
- ta_free(PTR_FROM_HEADER(eh->children.next));
+ while (eh->children.prev != &eh->children)
+ ta_free(PTR_FROM_HEADER(eh->children.prev));
}
/* Free the given allocation, and all of its direct and indirect children.