From 7078f232910ed7e4ee6a8306a8a154cfe4f4ccaf Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Wed, 20 Dec 2017 00:09:52 +0100 Subject: [PATCH] fix nil pointer on close(). --- app/log/log.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/log/log.go b/app/log/log.go index ae60def0..2f6932fc 100644 --- a/app/log/log.go +++ b/app/log/log.go @@ -11,6 +11,7 @@ import ( "v2ray.com/core/common/log" ) +// Instance is an app.Application that handles logs. type Instance struct { sync.RWMutex config *Config @@ -18,12 +19,14 @@ type Instance struct { errorLogger internal.LogWriter } +// New creates a new log.Instance based on the given config. func New(ctx context.Context, config *Config) (*Instance, error) { return &Instance{ config: config, }, nil } +// Interface implements app.Application.Interface(). func (*Instance) Interface() interface{} { return (*Instance)(nil) } @@ -58,6 +61,7 @@ func (g *Instance) initErrorLogger() error { return nil } +// Start implements app.Application.Start(). func (g *Instance) Start() error { if err := g.initAccessLogger(); err != nil { return newError("failed to initialize access logger").Base(err).AtWarning() @@ -69,6 +73,7 @@ func (g *Instance) Start() error { return nil } +// Handle implements log.Handler. func (g *Instance) Handle(msg log.Message) { switch msg := msg.(type) { case *log.AccessMessage: @@ -90,15 +95,20 @@ func (g *Instance) Handle(msg log.Message) { } } +// Close implement app.Application.Close(). func (g *Instance) Close() { g.Lock() defer g.Unlock() - g.accessLogger.Close() - g.accessLogger = nil + if g.accessLogger != nil { + g.accessLogger.Close() + g.accessLogger = nil + } - g.errorLogger.Close() - g.errorLogger = nil + if g.errorLogger != nil { + g.errorLogger.Close() + g.errorLogger = nil + } } func init() {