[PATCH 1/4] [mama] CPP Default queue tidy up


Ian Bell <IBell@...>
 

From b3579c20edd49597fd58e530be463611e61515f0 Mon Sep 17 00:00:00 2001

Message-Id: <b3579c20edd49597fd58e530be463611e61515f0.1348732807.git.ibell@...>

From: Ian Bell <ibell@...>

Date: Thu, 27 Sep 2012 08:41:41 +0100

Subject: [PATCH 1/4] [mama] CPP Default queue tidy up

 

Tidyup the cpp default queue wrapper to avoid memory leak /

core on shutdown.

 

Signed-off-by: Ian Bell <ibell@...>

---

mama/c_cpp/src/cpp/MamaQueue.cpp    |   10 +++++++++-

mama/c_cpp/src/cpp/mama/MamaQueue.h |    2 ++

mama/c_cpp/src/cpp/mamacpp.cpp      |    4 ++--

3 files changed, 13 insertions(+), 3 deletions(-)

 

diff --git a/mama/c_cpp/src/cpp/MamaQueue.cpp b/mama/c_cpp/src/cpp/MamaQueue.cpp

index b5b41db..abd880f 100644

--- a/mama/c_cpp/src/cpp/MamaQueue.cpp

+++ b/mama/c_cpp/src/cpp/MamaQueue.cpp

@@ -156,9 +156,11 @@ namespace Wombat

             : mClosure          (NULL)

             , mEnqueueCallback  (NULL)

                , mUserClosure      (NULL)

+             , mOwner                            (0)

         {

         }

+                             short                                                                       mOwner;

         void*                     mClosure;

         MamaQueueEnqueueCallback* mEnqueueCallback;

         MamaQueueMonitorCallback* mMonitorCallback;

@@ -174,6 +176,11 @@ namespace Wombat

     {

     }

+             MamaQueue::MamaQueue (mamaQueue cQueue)

+        : mPimpl (new MamaQueueImpl)

+        , mQueue (cQueue)

+    {

+    }

     MamaQueue::~MamaQueue (void)

     {

         destroy ();

@@ -183,6 +190,7 @@ namespace Wombat

     void MamaQueue::create (mamaBridge bridgeImpl)

     {

         mamaTry (mamaQueue_create (&mQueue, bridgeImpl));

+                             mPimpl->mOwner=1;

     }

     void MamaQueue::create (mamaBridge  bridgeImpl,

@@ -470,7 +478,7 @@ namespace Wombat

     {        

         mama_status status = MAMA_STATUS_OK;

-        if (mQueue)

+        if ((mQueue) && (mPimpl->mOwner))

         {

             status = mamaQueue_destroy (mQueue);       

         }

diff --git a/mama/c_cpp/src/cpp/mama/MamaQueue.h b/mama/c_cpp/src/cpp/mama/MamaQueue.h

index b49ff43..019d880 100644

--- a/mama/c_cpp/src/cpp/mama/MamaQueue.h

+++ b/mama/c_cpp/src/cpp/mama/MamaQueue.h

@@ -23,6 +23,7 @@

#define MAMA_QUEUE_CPP_H__

 #include <mama/mamacpp.h>

+#include <mama/queue.h>

 namespace Wombat

 {

@@ -41,6 +42,7 @@ namespace Wombat

     public:

         MamaQueue          (void);

+        MamaQueue          (mamaQueue cQueue);

         virtual ~MamaQueue (void);

         /**

diff --git a/mama/c_cpp/src/cpp/mamacpp.cpp b/mama/c_cpp/src/cpp/mamacpp.cpp

index 037f97b..6042e22 100644

--- a/mama/c_cpp/src/cpp/mamacpp.cpp

+++ b/mama/c_cpp/src/cpp/mamacpp.cpp

@@ -29,6 +29,7 @@

#include <string>

#include "MamaSubscriptionImpl.h"

#include <mama/queue.h>

+#include <mama/MamaQueue.h>

#include <mama/MamaReservedFields.h>

 namespace Wombat

@@ -283,8 +284,7 @@ namespace Wombat

             mamaQueue_getClosure (defaultQueueC, (void**)(&defaultQueue));

             if (defaultQueue == NULL)

             {

-                defaultQueue = new MamaQueue();

-                defaultQueue->setCValue(defaultQueueC);

+                defaultQueue = new MamaQueue(defaultQueueC);

                 mamaQueue_setClosure(defaultQueueC, (void*) defaultQueue);

             }

             return defaultQueue;

--

1.7.9.5

 




Please consider the environment before printing this e-mail.

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy.

Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

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