only free resources actually allocated (fixes #22)