Fix calculating free memory
Set a size of save resource as 0 if the buffer is NULL