Fixed memory leak when files/dirs error
Fixed memory leak when files/dirs error

Error path did not clean up after itself correctly

betzw/mbed-os,CalSol/mbed,kjbracey-arm/mbed,betzw/mbed-os,ryankurte/mbed-os,c1728p9/mbed-os,karsev/mbed-os,ryankurte/mbed-os,c1728p9/mbed-os,mazimkhan/mbed-os,Archcady/mbed-os,betzw/mbed-os,Archcady/mbed-os,karsev/mbed-os,ryankurte/mbed-os,mazimkhan/mbed-os,Archcady/mbed-os,kjbracey-arm/mbed,c1728p9/mbed-os,mbedmicro/mbed,betzw/mbed-os,karsev/mbed-os,andcor02/mbed-os,andcor02/mbed-os,Archcady/mbed-os,karsev/mbed-os,CalSol/mbed,betzw/mbed-os,c1728p9/mbed-os,CalSol/mbed,Archcady/mbed-os,ryankurte/mbed-os,Archcady/mbed-os,CalSol/mbed,mazimkhan/mbed-os,andcor02/mbed-os,mbedmicro/mbed,kjbracey-arm/mbed,karsev/mbed-os,ryankurte/mbed-os,betzw/mbed-os,mbedmicro/mbed,andcor02/mbed-os,karsev/mbed-os,mbedmicro/mbed,CalSol/mbed,c1728p9/mbed-os,CalSol/mbed,andcor02/mbed-os,c1728p9/mbed-os,mazimkhan/mbed-os,mazimkhan/mbed-os,mazimkhan/mbed-os,kjbracey-arm/mbed,ryankurte/mbed-os,andcor02/mbed-os,mbedmicro/mbed