I was creating a local variable shadowing the global one. This prevented cleanup to close it. (this is not really necessary as the program dies anyway)