cleanup allocated memory on error

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