Fix use after free and conditional jump on uninitialized