Fix memory leaks and cope with NULL aor_data.