osaf/libs/agents/saf/amfa/amf_agent.cc |  17 ++++++++++++++---
 osaf/libs/agents/saf/amfa/ava_hdl.cc   |  16 +++++++---------
 2 files changed, 21 insertions(+), 12 deletions(-)


diff --git a/osaf/libs/agents/saf/amfa/amf_agent.cc 
b/osaf/libs/agents/saf/amfa/amf_agent.cc
--- a/osaf/libs/agents/saf/amfa/amf_agent.cc
+++ b/osaf/libs/agents/saf/amfa/amf_agent.cc
@@ -2457,11 +2457,18 @@ SaAisErrorT AmfAgent::ProtectionGroupTra
         /* create_momory is true, so let us create the memory for the Use, 
User has to free it. */
         buf->numberOfItems = rsp_buf->numberOfItems;
         if (buf->numberOfItems != 0) {
+                       /*
+                        * NOTE: This buf->notification is allocated by Agent, 
it's
+                        * added sentinel element at the end so that it helps
+                        * to free LongDn in 
saAmfProtectionGroupNotificationFree_4
+                        * Sentinel element has @.change = 0
+                        */
           buf->notification =
-              
static_cast<SaAmfProtectionGroupNotificationT_4*>(malloc(buf->numberOfItems * 
sizeof(SaAmfProtectionGroupNotificationT_4)));
+              
static_cast<SaAmfProtectionGroupNotificationT_4*>(malloc((buf->numberOfItems + 
1) * sizeof(SaAmfProtectionGroupNotificationT_4)));
           if (buf->notification != NULL) {
             ava_cpy_protection_group_ntf(buf->notification, 
rsp_buf->notification,
                                          buf->numberOfItems, 
SA_AMF_HARS_READY_FOR_ASSIGNMENT);
+            buf->notification[buf->numberOfItems].change = 
static_cast<SaAmfProtectionGroupChangesT>(0);
           } else {
             rc = SA_AIS_ERR_NO_MEMORY;
             buf->numberOfItems = 0;
@@ -2555,8 +2562,12 @@ SaAisErrorT AmfAgent::ProtectionGroupNot
 
   /* free memory */
   if(notification) {
-    // TODO (minhchau): memleak if notification is an array
-    osaf_extended_name_free(&notification->member.compName);
+    // Free LongDn until reach sentinel element
+       int i = 0;
+       while (notification[i].change != 0) {
+               osaf_extended_name_free(&notification[i].member.compName);
+               i++;
+       }
     free(notification);
   }
   else
diff --git a/osaf/libs/agents/saf/amfa/ava_hdl.cc 
b/osaf/libs/agents/saf/amfa/ava_hdl.cc
--- a/osaf/libs/agents/saf/amfa/ava_hdl.cc
+++ b/osaf/libs/agents/saf/amfa/ava_hdl.cc
@@ -680,19 +680,17 @@ uint32_t ava_hdl_cbk_rec_prc(AVSV_AMF_CB
                                        /* copy the contents into a malloced 
buffer.. appl frees it */
                                        buf.numberOfItems = 
pg_track->buf.numberOfItems;
                                        buf.notification =
-                                               
static_cast<SaAmfProtectionGroupNotificationT_4*>(malloc(buf.numberOfItems * 
sizeof(SaAmfProtectionGroupNotificationT_4)));
+                                               
static_cast<SaAmfProtectionGroupNotificationT_4*>(malloc((buf.numberOfItems+1) 
* sizeof(SaAmfProtectionGroupNotificationT_4)));
                                        if (buf.notification) {
                                                
ava_cpy_protection_group_ntf(buf.notification, pg_track->buf.notification,
                                                                
pg_track->buf.numberOfItems, SA_AMF_HARS_READY_FOR_ASSIGNMENT);
-
-                                               /* allocate LongDn strings for 
notification if any
-                                                * then client needs to free 
these LongDn string as well
+                                               /*
+                                                * NOTE: This buf->notification 
is allocated by Agent, it's
+                                                * added sentinel element at 
the end so that it helps
+                                                * to free LongDn in 
saAmfProtectionGroupNotificationFree_4
+                                                * Sentinel element has 
@.change = 0
                                                 */
-                                               for (i=0 ; i < 
buf.numberOfItems; i++) {
-                                                       
osaf_extended_name_alloc(
-                                                               
osaf_extended_name_borrow(&pg_track->buf.notification[i].member.compName),
-                                                               
&buf.notification[i].member.compName);
-                                               }
+                                   buf.notification[buf.numberOfItems].change 
= static_cast<SaAmfProtectionGroupChangesT>(0);
                                                TRACE("Invoking PGTrack 
callback for CSIName = %s", osaf_extended_name_borrow(&pg_track->csi_name));
                                                
((SaAmfCallbacksT_4*)reg_cbk)->saAmfProtectionGroupTrackCallback(&pg_track->csi_name,
                                                                                
                        &buf,

------------------------------------------------------------------------------
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to