Fix memory leak when maintaining resources. When extra resources are