[SPARK-4663][sql]add finally to avoid resource leak

indent only 2 spaces here.