fix resource leak

Signed-off-by: Zeying Xie <swpdtz@gmail.com>