add cleanup in allocate_resources()