From cf133fed7d2f90cf15b9e4d002dc3ad5d61eee74 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Fri, 4 May 2018 20:12:32 +0800 Subject: [PATCH] eth/filter: check nil pointer when unsubscribe --- eth/filters/filter_system.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/eth/filters/filter_system.go b/eth/filters/filter_system.go index f8097c7b95ea..7a7eb76c20da 100644 --- a/eth/filters/filter_system.go +++ b/eth/filters/filter_system.go @@ -428,12 +428,24 @@ func (es *EventSystem) eventLoop() { chainEvSub = es.backend.SubscribeChainEvent(chainEvCh) ) - // Unsubscribe all events - defer sub.Unsubscribe() - defer txSub.Unsubscribe() - defer rmLogsSub.Unsubscribe() - defer logsSub.Unsubscribe() - defer chainEvSub.Unsubscribe() + defer func() { + // Unsubscribe all events + if sub != nil { + sub.Unsubscribe() + } + if txSub != nil { + txSub.Unsubscribe() + } + if rmLogsSub != nil { + rmLogsSub.Unsubscribe() + } + if logsSub != nil { + logsSub.Unsubscribe() + } + if chainEvSub != nil { + chainEvSub.Unsubscribe() + } + }() for i := UnknownSubscription; i < LastIndexSubscription; i++ { index[i] = make(map[rpc.ID]*subscription)