Fix freeing resources in some tests and dev-tools so we can run unit-tests with enabled file-leak-detector