Fix potential memory leak of handler