[PATCH 2/5] MamaDQPublisherManger create/destroy fixes


Ian Bell <IBell@...>
 

From 5800de3d24d1a61ab94222826ae63597ec53534c Mon Sep 17 00:00:00 2001

Message-Id: <5800de3d24d1a61ab94222826ae63597ec53534c.1348577193.git.ibell@...>

In-Reply-To: <c6056d16f347a98054cb70348d5fbcc988abbf60.1348577193.git.ibell@...>

References: <c6056d16f347a98054cb70348d5fbcc988abbf60.1348577193.git.ibell@...>

From: Ian Bell <ibell@...>

Date: Tue, 25 Sep 2012 13:26:01 +0100

Subject: [PATCH 2/5] MamaDQPublisherManger create/destroy fixes

 

Previously the namespace for the dqpublishermanager was limited ot 80 chars,

and settings were not passed down from publishermanager to pbulishers

correctly. Also fixed memory leak on shutdown.

 

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

---

mama/c_cpp/src/c/dqpublisher.c        |   45 ++++++++++++++++-----------------

mama/c_cpp/src/c/dqpublishermanager.c |   22 +++++++++++-----

2 files changed, 38 insertions(+), 29 deletions(-)

 

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

index d782548..c2780aa 100644

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

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

@@ -44,7 +44,11 @@ mama_status mamaDQPublisher_allocate (mamaDQPublisher* result)

     impl = (mamaDQPublisherImpl*)calloc (1, sizeof (mamaDQPublisherImpl));

     if (!impl) return MAMA_STATUS_NOMEM;

-   

+       

+    impl->mSenderId = mamaSenderId_getSelf ();

+    impl->mStatus = MAMA_MSG_STATUS_OK;

+    impl->mSeqNum = 1;

+

     *result = impl;

     return MAMA_STATUS_OK;

@@ -62,13 +66,6 @@ mama_status mamaDQPublisher_create (mamaDQPublisher pub, mamaTransport transport

                            topic,

                            NULL,

                            NULL);

-

-    if (status == MAMA_STATUS_OK)

-    {

-        impl->mSenderId = mamaSenderId_getSelf ();

-        impl->mStatus = MAMA_MSG_STATUS_OK;

-        impl->mSeqNum = 1;

-    }

    

     return status;

}

@@ -158,14 +155,7 @@ mama_status mamaDQPublisher_sendReply (mamaDQPublisher pub,

                                        mamaMsg reply)

{

     mamaDQPublisherImpl* impl = (mamaDQPublisherImpl*) (pub);

-

-    if(MAMA_STATUS_OK != mamaMsg_updateU8(reply,MamaFieldMsgStatus.mName,

-                MamaFieldMsgStatus.mFid, impl->mStatus))

-    {

-        mamaMsg_updateI16(reply,MamaFieldMsgStatus.mName,

-                MamaFieldMsgStatus.mFid, impl->mStatus);

-    }

-   

+  

     if (impl->mSenderId != 0)

     {

             mamaMsgField senderIdField = NULL;

@@ -206,6 +196,13 @@ mama_status mamaDQPublisher_sendReply (mamaDQPublisher pub,

     {

         mamaMsg_updateU32(reply, MamaFieldSeqNum.mName, MamaFieldSeqNum.mFid,

                 impl->mSeqNum);

+

+        if(MAMA_STATUS_OK != mamaMsg_updateU8(reply,MamaFieldMsgStatus.mName,

+                MamaFieldMsgStatus.mFid, impl->mStatus))

+        {

+            mamaMsg_updateI16(reply,MamaFieldMsgStatus.mName,

+                MamaFieldMsgStatus.mFid, impl->mStatus);

+        }

     }

     return (mamaPublisher_sendReplyToInbox (impl->mPublisher, request, reply));

@@ -217,13 +214,6 @@ mama_status mamaDQPublisher_sendReplyWithHandle (mamaDQPublisher pub,

{

     mamaDQPublisherImpl* impl = (mamaDQPublisherImpl*) (pub);

-    if(MAMA_STATUS_OK != mamaMsg_updateU8(reply,MamaFieldMsgStatus.mName,

-                MamaFieldMsgStatus.mFid, impl->mStatus))

-    {

-        mamaMsg_updateI16(reply,MamaFieldMsgStatus.mName,

-                MamaFieldMsgStatus.mFid, impl->mStatus);

-    }

-

     if (impl->mSenderId != 0)

     {

             mamaMsgField senderIdField = NULL;

@@ -264,6 +254,13 @@ mama_status mamaDQPublisher_sendReplyWithHandle (mamaDQPublisher pub,

     {

         mamaMsg_updateU32(reply, MamaFieldSeqNum.mName, MamaFieldSeqNum.mFid,

                 impl->mSeqNum);

+

+        if(MAMA_STATUS_OK != mamaMsg_updateU8(reply,MamaFieldMsgStatus.mName,

+                    MamaFieldMsgStatus.mFid, impl->mStatus))

+        {

+            mamaMsg_updateI16(reply,MamaFieldMsgStatus.mName,

+                    MamaFieldMsgStatus.mFid, impl->mStatus);

+        }

     }

     return (mamaPublisher_sendReplyToInboxHandle (impl->mPublisher,

@@ -279,6 +276,8 @@ void mamaDQPublisher_destroy (mamaDQPublisher pub)

         mamaPublisher_destroy (impl->mPublisher);

         impl->mPublisher = NULL;

     }

+

+    free(impl);

}

 

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

index 3aaf061..4611a87 100644

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

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

@@ -250,7 +250,8 @@ mama_status mamaDQPublisherManager_create (

         const char* root,

         void * closure)

{

-    char topic[80];

+    char* topic;

+    int length = 0;

     mamaDQPublisherManagerImpl* impl  = (mamaDQPublisherManagerImpl*) manager;

     static mamaMsgCallbacks basicSubscCbs =

     {

@@ -264,6 +265,8 @@ mama_status mamaDQPublisherManager_create (

     impl->mTransport = transport;

     impl->mQueue = queue;

     impl->mClosure = closure;

+    length = strlen(root) + 1 + (strlen(sourcename) + 1);

+    topic = calloc(length, sizeof(char));

     strcpy(topic, root);

     impl->mNameSpace =  strdup(sourcename);

@@ -283,6 +286,7 @@ mama_status mamaDQPublisherManager_create (

                                    &basicSubscCbs,

                                    topic,

                                    impl);

+    free(topic);

     return MAMA_STATUS_OK;

}

@@ -404,7 +408,8 @@ mama_status mamaDQPublisherManager_createPublisher (

     mamaDQPublisherManagerImpl* impl  = (mamaDQPublisherManagerImpl*) manager;

     mamaPublishTopic* newTopic = NULL;

     mama_status status = MAMA_STATUS_OK;

-    char topic[80];

+    char* topic;

+    int length = 0;

     newTopic =  (mamaPublishTopic*)wtable_lookup (impl->mPublisherMap, (char*)symbol);

@@ -418,6 +423,13 @@ mama_status mamaDQPublisherManager_createPublisher (

             newTopic->cache = cache;

             newTopic->symbol = strdup(symbol);

+            mamaDQPublisher_setCache(*newPublisher, cache);

+            mamaDQPublisher_setSenderId(*newPublisher,  impl->mSenderId);

+            mamaDQPublisher_setStatus(*newPublisher,  impl->mStatus);

+            mamaDQPublisher_setSeqNum(*newPublisher, impl->mSeqNum);

+

+            length = strlen(impl->mNameSpace) + 1 + (strlen(symbol) + 1);

+            topic = calloc(length, sizeof(char));

             strcpy (topic, impl->mNameSpace);

             strcat (topic, ".");

             strcat (topic, symbol);

@@ -425,13 +437,11 @@ mama_status mamaDQPublisherManager_createPublisher (

             if ((status = mamaDQPublisher_create(*newPublisher,

                             impl->mTransport, topic)) != MAMA_STATUS_OK)

             {

+                free (topic);

                 return status;

             }

+            free (topic);

-            mamaDQPublisher_setCache(*newPublisher, cache);

-            mamaDQPublisher_setSenderId(*newPublisher,  impl->mSenderId);

-            mamaDQPublisher_setStatus(*newPublisher,  impl->mStatus);

-            mamaDQPublisher_setSeqNum(*newPublisher, impl->mSeqNum);

             if (wtable_insert  (impl->mPublisherMap, (char*)symbol, newTopic) != 1)

             {

                 mamaDQPublisher_destroy(*newPublisher);

--

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.


Ian Bell <IBell@...>
 

Attached patch

 

From: openmama-dev-bounces@... [mailto:openmama-dev-bounces@...] On Behalf Of Ian Bell
Sent: 25 September 2012 13:49
To: openmama-dev@...
Subject: [Openmama-dev] [PATCH 2/5] MamaDQPublisherManger create/destroy fixes

 

From 5800de3d24d1a61ab94222826ae63597ec53534c Mon Sep 17 00:00:00 2001

Message-Id: <5800de3d24d1a61ab94222826ae63597ec53534c.1348577193.git.ibell@...>

In-Reply-To: <c6056d16f347a98054cb70348d5fbcc988abbf60.1348577193.git.ibell@...>

References: <c6056d16f347a98054cb70348d5fbcc988abbf60.1348577193.git.ibell@...>

From: Ian Bell <ibell@...>

Date: Tue, 25 Sep 2012 13:26:01 +0100

Subject: [PATCH 2/5] MamaDQPublisherManger create/destroy fixes

 

Previously the namespace for the dqpublishermanager was limited ot 80 chars,

and settings were not passed down from publishermanager to pbulishers

correctly. Also fixed memory leak on shutdown.

 

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

---

mama/c_cpp/src/c/dqpublisher.c        |   45 ++++++++++++++++-----------------

mama/c_cpp/src/c/dqpublishermanager.c |   22 +++++++++++-----

2 files changed, 38 insertions(+), 29 deletions(-)

 

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

index d782548..c2780aa 100644

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

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

@@ -44,7 +44,11 @@ mama_status mamaDQPublisher_allocate (mamaDQPublisher* result)

     impl = (mamaDQPublisherImpl*)calloc (1, sizeof (mamaDQPublisherImpl));

     if (!impl) return MAMA_STATUS_NOMEM;

-   

+       

+    impl->mSenderId = mamaSenderId_getSelf ();

+    impl->mStatus = MAMA_MSG_STATUS_OK;

+    impl->mSeqNum = 1;

+

     *result = impl;

     return MAMA_STATUS_OK;

@@ -62,13 +66,6 @@ mama_status mamaDQPublisher_create (mamaDQPublisher pub, mamaTransport transport

                            topic,

                            NULL,

                            NULL);

-

-    if (status == MAMA_STATUS_OK)

-    {

-        impl->mSenderId = mamaSenderId_getSelf ();

-        impl->mStatus = MAMA_MSG_STATUS_OK;

-        impl->mSeqNum = 1;

-    }

    

     return status;

}

@@ -158,14 +155,7 @@ mama_status mamaDQPublisher_sendReply (mamaDQPublisher pub,

                                        mamaMsg reply)

{

     mamaDQPublisherImpl* impl = (mamaDQPublisherImpl*) (pub);

-

-    if(MAMA_STATUS_OK != mamaMsg_updateU8(reply,MamaFieldMsgStatus.mName,

-                MamaFieldMsgStatus.mFid, impl->mStatus))

-    {

-        mamaMsg_updateI16(reply,MamaFieldMsgStatus.mName,

-                MamaFieldMsgStatus.mFid, impl->mStatus);

-    }

-   

+  

     if (impl->mSenderId != 0)

     {

             mamaMsgField senderIdField = NULL;

@@ -206,6 +196,13 @@ mama_status mamaDQPublisher_sendReply (mamaDQPublisher pub,

     {

         mamaMsg_updateU32(reply, MamaFieldSeqNum.mName, MamaFieldSeqNum.mFid,

                 impl->mSeqNum);

+

+        if(MAMA_STATUS_OK != mamaMsg_updateU8(reply,MamaFieldMsgStatus.mName,

+                MamaFieldMsgStatus.mFid, impl->mStatus))

+        {

+            mamaMsg_updateI16(reply,MamaFieldMsgStatus.mName,

+                MamaFieldMsgStatus.mFid, impl->mStatus);

+        }

     }

     return (mamaPublisher_sendReplyToInbox (impl->mPublisher, request, reply));

@@ -217,13 +214,6 @@ mama_status mamaDQPublisher_sendReplyWithHandle (mamaDQPublisher pub,

{

     mamaDQPublisherImpl* impl = (mamaDQPublisherImpl*) (pub);

-    if(MAMA_STATUS_OK != mamaMsg_updateU8(reply,MamaFieldMsgStatus.mName,

-                MamaFieldMsgStatus.mFid, impl->mStatus))

-    {

-        mamaMsg_updateI16(reply,MamaFieldMsgStatus.mName,

-                MamaFieldMsgStatus.mFid, impl->mStatus);

-    }

-

     if (impl->mSenderId != 0)

     {

             mamaMsgField senderIdField = NULL;

@@ -264,6 +254,13 @@ mama_status mamaDQPublisher_sendReplyWithHandle (mamaDQPublisher pub,

     {

         mamaMsg_updateU32(reply, MamaFieldSeqNum.mName, MamaFieldSeqNum.mFid,

                 impl->mSeqNum);

+

+        if(MAMA_STATUS_OK != mamaMsg_updateU8(reply,MamaFieldMsgStatus.mName,

+                    MamaFieldMsgStatus.mFid, impl->mStatus))

+        {

+            mamaMsg_updateI16(reply,MamaFieldMsgStatus.mName,

+                    MamaFieldMsgStatus.mFid, impl->mStatus);

+        }

     }

     return (mamaPublisher_sendReplyToInboxHandle (impl->mPublisher,

@@ -279,6 +276,8 @@ void mamaDQPublisher_destroy (mamaDQPublisher pub)

         mamaPublisher_destroy (impl->mPublisher);

         impl->mPublisher = NULL;

     }

+

+    free(impl);

}

 

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

index 3aaf061..4611a87 100644

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

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

@@ -250,7 +250,8 @@ mama_status mamaDQPublisherManager_create (

         const char* root,

         void * closure)

{

-    char topic[80];

+    char* topic;

+    int length = 0;

     mamaDQPublisherManagerImpl* impl  = (mamaDQPublisherManagerImpl*) manager;

     static mamaMsgCallbacks basicSubscCbs =

     {

@@ -264,6 +265,8 @@ mama_status mamaDQPublisherManager_create (

     impl->mTransport = transport;

     impl->mQueue = queue;

     impl->mClosure = closure;

+    length = strlen(root) + 1 + (strlen(sourcename) + 1);

+    topic = calloc(length, sizeof(char));

     strcpy(topic, root);

     impl->mNameSpace =  strdup(sourcename);

@@ -283,6 +286,7 @@ mama_status mamaDQPublisherManager_create (

                                    &basicSubscCbs,

                                    topic,

                                    impl);

+    free(topic);

     return MAMA_STATUS_OK;

}

@@ -404,7 +408,8 @@ mama_status mamaDQPublisherManager_createPublisher (

     mamaDQPublisherManagerImpl* impl  = (mamaDQPublisherManagerImpl*) manager;

     mamaPublishTopic* newTopic = NULL;

     mama_status status = MAMA_STATUS_OK;

-    char topic[80];

+    char* topic;

+    int length = 0;

     newTopic =  (mamaPublishTopic*)wtable_lookup (impl->mPublisherMap, (char*)symbol);

@@ -418,6 +423,13 @@ mama_status mamaDQPublisherManager_createPublisher (

             newTopic->cache = cache;

             newTopic->symbol = strdup(symbol);

+            mamaDQPublisher_setCache(*newPublisher, cache);

+            mamaDQPublisher_setSenderId(*newPublisher,  impl->mSenderId);

+            mamaDQPublisher_setStatus(*newPublisher,  impl->mStatus);

+            mamaDQPublisher_setSeqNum(*newPublisher, impl->mSeqNum);

+

+            length = strlen(impl->mNameSpace) + 1 + (strlen(symbol) + 1);

+            topic = calloc(length, sizeof(char));

             strcpy (topic, impl->mNameSpace);

             strcat (topic, ".");

             strcat (topic, symbol);

@@ -425,13 +437,11 @@ mama_status mamaDQPublisherManager_createPublisher (

             if ((status = mamaDQPublisher_create(*newPublisher,

                             impl->mTransport, topic)) != MAMA_STATUS_OK)

             {

+                free (topic);

                 return status;

             }

+            free (topic);

-            mamaDQPublisher_setCache(*newPublisher, cache);

-            mamaDQPublisher_setSenderId(*newPublisher,  impl->mSenderId);

-            mamaDQPublisher_setStatus(*newPublisher,  impl->mStatus);

-            mamaDQPublisher_setSeqNum(*newPublisher, impl->mSeqNum);

             if (wtable_insert  (impl->mPublisherMap, (char*)symbol, newTopic) != 1)

             {

                 mamaDQPublisher_destroy(*newPublisher);

--

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.




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.