Fix the double free issue using the official libelf API.