Fixed memory leak caused by exception in @shutdown handler.