cleanup allocated memory on error

(cherry picked from commit 4979d5f3)
18 jobs for 703-resource-leak-in-dlz_filesystem_driver-c-v9_11 in 8 minutes and 5 seconds (queued for 4 seconds)