From: Irina Date: Mon, 6 Jan 2020 13:36:11 +0000 (+0200) Subject: RICPLT-2966 - Free memory fix cgo X-Git-Tag: R5_RC~132 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;ds=sidebyside;h=refs%2Fchanges%2F57%2F2157%2F1;p=ric-plt%2Fe2mgr.git RICPLT-2966 - Free memory fix cgo Change-Id: Ie07be64ac104fe9cfbaa96faab8e69d0bf8d7206 Signed-off-by: Irina --- diff --git a/E2Manager/rmrCgo/rmrCgoApi.go b/E2Manager/rmrCgo/rmrCgoApi.go index f65d10d..308ab63 100644 --- a/E2Manager/rmrCgo/rmrCgoApi.go +++ b/E2Manager/rmrCgo/rmrCgoApi.go @@ -61,7 +61,6 @@ func (ctx *Context) SendMsg(msg *MBuf, printLogs bool) (*MBuf, error) { ctx.checkContextInitialized() ctx.Logger.Debugf("#rmrCgoApi.SendMsg - Going to send message. MBuf: %v", *msg) allocatedCMBuf := ctx.getAllocatedCRmrMBuf(ctx.Logger, msg, ctx.MaxMsgSize) - defer C.rmr_free_msg(allocatedCMBuf) state := allocatedCMBuf.state if state != RMR_OK { errorMessage := fmt.Sprintf("#rmrCgoApi.SendMsg - Failed to get allocated message. state: %v - %s", state, states[int(state)]) @@ -76,6 +75,8 @@ func (ctx *Context) SendMsg(msg *MBuf, printLogs bool) (*MBuf, error) { } currCMBuf := C.rmr_send_msg(ctx.RmrCtx, allocatedCMBuf) + defer C.rmr_free_msg(currCMBuf) + state = currCMBuf.state if state != RMR_OK { @@ -90,9 +91,10 @@ func (ctx *Context) RecvMsg() (*MBuf, error) { ctx.checkContextInitialized() ctx.Logger.Debugf("#rmrCgoApi.RecvMsg - Going to receive message") allocatedCMBuf := C.rmr_alloc_msg(ctx.RmrCtx, C.int(ctx.MaxMsgSize)) - defer C.rmr_free_msg(allocatedCMBuf) currCMBuf := C.rmr_rcv_msg(ctx.RmrCtx, allocatedCMBuf) + defer C.rmr_free_msg(currCMBuf) + state := currCMBuf.state if state != RMR_OK { @@ -121,4 +123,4 @@ func (ctx *Context) Close() { ctx.Logger.Debugf("#rmrCgoApi.Close - Going to close RMR context") C.rmr_close(ctx.RmrCtx) time.Sleep(100 * time.Millisecond) -} +} \ No newline at end of file