[PATCH]Fix memleak in mamaMsgImpl_setPayload


Benjamin Taieb
 

Hi List,

Attached is a patch fixing a memleak in mamaMsgImpl_setPayload.

impl->payload is not checked for a owned previous payload before the assignment, leading to a memory leak, in particular was showing when using mamaMsgField_getMsg.

 

 

diff --git a/mama/c_cpp/src/c/msg.c b/mama/c_cpp/src/c/msg.c

index 286fcad..0dc5317 100644

--- a/mama/c_cpp/src/c/msg.c

+++ b/mama/c_cpp/src/c/msg.c

@@ -444,6 +444,20 @@ mamaMsgImpl_setPayload (mamaMsg msg, msgPayload payload, short owner)

         /* Do not destroy the list. We can reuse the memory! */

     }

+  if (impl->mPayload && impl->mPayloadBridge && impl->mMessageOwner)

+    {

+        if (MAMA_STATUS_OK != impl->mPayloadBridge->msgPayloadDestroy (impl->mPayload))

+        {

+            mama_log (MAMA_LOG_LEVEL_ERROR, "mamaMsgImpl_setPayload(): "

+                     "Could not destroy message payload.");

+        }

+            

+

+        /*set mMessageOwner to zero now the payload has been destroyed to prevent

+          us destroying the underlying message again in the bridge specific function*/

+        impl->mMessageOwner = 0;

+    }

+

     impl->mPayload      = payload;

     impl->mMessageOwner = owner;

     impl->mPayloadBridge->msgPayloadSetParent (impl->mPayload, msg);

 

 

 

Please review,

Benjamin Taieb.

Join Openmama-dev@lists.openmama.org to automatically receive all group messages.