Fix socket leaks

During tests Python warned of a socket not being closed. These were
mainly in the tests themselves, but there was one problem where I
changed the driver itself.