fix: fixed some leaks
fix: progname is const, do not free it

The leak is irrelevant
fix: now CloseConnections() is much more safe