fixed memleak when receiving invalid certificate