Fixed possible ressource leaks.