The huge potential for leaks here makes _some_ kind of automatic cleanup necessary.

I mean, this code is _still_ leaking in some cases. It's truly hard to get right without scoped cleanup.