Fix segmentation fault when handler is NULL pointer

Signed-off-by: Haomai Wang <haomaiwang@gmail.com>