Additional memory leak / invalid read fixes in production code