Fix deadlock and leaks in callback example.