Fix some double-frees/use-after-free

r? @frank-trampe
Gotos are not inherently wrong, they are used a lot in the Linux Kernel as exit paths in functions. And I think that it's the right use-case for them. They have been condemned in the 70s (I think?) because people used them too much and for everything. This here is okay if you ask me, and it avoid unnecessary code duplication.