Code violation fix 27/4827/1 v0.5.6
authorJuha Hyttinen <juha.hyttinen@nokia.com>
Fri, 9 Oct 2020 06:51:12 +0000 (09:51 +0300)
committerJuha Hyttinen <juha.hyttinen@nokia.com>
Fri, 9 Oct 2020 06:51:21 +0000 (09:51 +0300)
Change-Id: Iebf70874d45c31879f8679b04f3a3e1ea3ed8851
Signed-off-by: Juha Hyttinen <juha.hyttinen@nokia.com>
pkg/xapp/rmr.go

index 03fba67..8e9faef 100755 (executable)
@@ -409,8 +409,7 @@ func (m *RMRClient) Send(params *RMRParams, isRts bool) bool {
 
 func (m *RMRClient) SendBuf(txBuffer *C.rmr_mbuf_t, isRts bool, whid int) int {
        var (
-               currBuffer  *C.rmr_mbuf_t
-               counterName string = "Transmitted"
+               currBuffer *C.rmr_mbuf_t
        )
 
        m.contextMux.Lock()
@@ -451,15 +450,21 @@ func (m *RMRClient) SendBuf(txBuffer *C.rmr_mbuf_t, isRts bool, whid int) int {
                m.contextMux.Unlock()
        }
 
-       if currBuffer.state != C.RMR_OK {
-               counterName = "TransmitError"
+       if currBuffer == nil {
+               m.UpdateStatCounter("TransmitError")
                m.LogMBufError("SendBuf failed", currBuffer)
+               return int(C.RMR_ERR_INITFAILED)
        }
 
-       m.UpdateStatCounter(counterName)
+       if currBuffer.state != C.RMR_OK {
+               m.UpdateStatCounter("TransmitError")
+               m.LogMBufError("SendBuf failed", currBuffer)
+       } else {
+               m.UpdateStatCounter("Transmitted")
+       }
        defer m.Free(currBuffer)
-
        return int(currBuffer.state)
+
 }
 
 func (m *RMRClient) SendCallMsg(params *RMRParams) (int, string) {