Fix ZTS build + memory leak