Fix possible UDF deadlock and memory corruption (CVE-2006-4145)