From 888a732fbc9b16c7776f78f147d9277641fc61ca Mon Sep 17 00:00:00 2001 From: Danny Shemesh Date: Mon, 14 Oct 2024 11:48:59 +0300 Subject: [PATCH] Unlock memguard global change mutex only when locked (#5714) --- pkg/protocols/common/protocolstate/memguardian.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/protocols/common/protocolstate/memguardian.go b/pkg/protocols/common/protocolstate/memguardian.go index 1db1e0a775..b5c8cffc75 100644 --- a/pkg/protocols/common/protocolstate/memguardian.go +++ b/pkg/protocols/common/protocolstate/memguardian.go @@ -77,9 +77,8 @@ var muGlobalChange sync.Mutex // Global setting func GlobalGuardBytesBufferAlloc() error { - if muGlobalChange.TryLock() { + if !muGlobalChange.TryLock() { return nil - } defer muGlobalChange.Unlock() @@ -95,9 +94,8 @@ func GlobalGuardBytesBufferAlloc() error { // Global setting func GlobalRestoreBytesBufferAlloc() { - if muGlobalChange.TryLock() { + if !muGlobalChange.TryLock() { return - } defer muGlobalChange.Unlock()