Fixed memory and thread leak in dht lib