Fix #325 - don't leak references in client shutdown code