diff --git a/decoders/netflow/netflow.go b/decoders/netflow/netflow.go index e551e7a..adb0543 100644 --- a/decoders/netflow/netflow.go +++ b/decoders/netflow/netflow.go @@ -285,6 +285,7 @@ func (ts *BasicTemplateSystem) GetTemplates() map[uint16]map[uint32]map[uint16]i func (ts *BasicTemplateSystem) AddTemplate(version uint16, obsDomainId uint32, template interface{}) { ts.templateslock.Lock() + defer ts.templateslock.Unlock() _, exists := ts.templates[version] if exists != true { ts.templates[version] = make(map[uint32]map[uint16]interface{}) @@ -303,27 +304,21 @@ func (ts *BasicTemplateSystem) AddTemplate(version uint16, obsDomainId uint32, t templateId = templateIdConv.TemplateId } ts.templates[version][obsDomainId][templateId] = template - ts.templateslock.Unlock() } func (ts *BasicTemplateSystem) GetTemplate(version uint16, obsDomainId uint32, templateId uint16) (interface{}, error) { ts.templateslock.RLock() + defer ts.templateslock.RUnlock() templatesVersion, okver := ts.templates[version] if okver { templatesObsDom, okobs := templatesVersion[obsDomainId] if okobs { template, okid := templatesObsDom[templateId] if okid { - ts.templateslock.RUnlock() return template, nil } - ts.templateslock.RUnlock() - return nil, NewErrorTemplateNotFound(version, obsDomainId, templateId, "info") } - ts.templateslock.RUnlock() - return nil, NewErrorTemplateNotFound(version, obsDomainId, templateId, "info") } - ts.templateslock.RUnlock() return nil, NewErrorTemplateNotFound(version, obsDomainId, templateId, "info") } diff --git a/format/format.go b/format/format.go index 6ea431b..5edf057 100644 --- a/format/format.go +++ b/format/format.go @@ -53,12 +53,12 @@ func FindFormat(ctx context.Context, name string) (*Format, error) { func GetFormats() []string { lock.RLock() + defer lock.RUnlock() t := make([]string, len(formatDrivers)) var i int for k, _ := range formatDrivers { t[i] = k i++ } - lock.RUnlock() return t } diff --git a/producer/producer_nf.go b/producer/producer_nf.go index 2af3967..685206e 100644 --- a/producer/producer_nf.go +++ b/producer/producer_nf.go @@ -33,27 +33,25 @@ func CreateSamplingSystem() SamplingRateSystem { func (s *basicSamplingRateSystem) AddSamplingRate(version uint16, obsDomainId uint32, samplingRate uint32) { s.samplinglock.Lock() + defer s.samplinglock.Unlock() _, exists := s.sampling[version] if exists != true { s.sampling[version] = make(map[uint32]uint32) } s.sampling[version][obsDomainId] = samplingRate - s.samplinglock.Unlock() } func (s *basicSamplingRateSystem) GetSamplingRate(version uint16, obsDomainId uint32) (uint32, error) { s.samplinglock.RLock() + defer s.samplinglock.RUnlock() samplingVersion, okver := s.sampling[version] if okver { samplingRate, okid := samplingVersion[obsDomainId] if okid { - s.samplinglock.RUnlock() return samplingRate, nil } - s.samplinglock.RUnlock() return 0, errors.New("") // TBC } - s.samplinglock.RUnlock() return 0, errors.New("") // TBC } diff --git a/transport/transport.go b/transport/transport.go index e133d65..11e9c67 100644 --- a/transport/transport.go +++ b/transport/transport.go @@ -57,12 +57,12 @@ func FindTransport(ctx context.Context, name string) (*Transport, error) { func GetTransports() []string { lock.RLock() + defer lock.RUnlock() t := make([]string, len(transportDrivers)) var i int for k, _ := range transportDrivers { t[i] = k i++ } - lock.RUnlock() return t }