Add handling for error case in GroupManager::getActionSetfromString.
authorAnkur Bansal <ankur.b1@samsung.com>
Sat, 4 Jul 2015 13:08:08 +0000 (18:38 +0530)
committerUze Choi <uzchoi@samsung.com>
Tue, 7 Jul 2015 09:54:26 +0000 (09:54 +0000)
Delete action in case something went wrong during parsing.

Change-Id: I0e72db223ef21d0e89351d238532e168b2ca1177
Signed-off-by: Ankur Bansal <ankur.b1@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1523
Reviewed-by: Jihun Ha <jihun.ha@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/things-manager/sdk/src/GroupManager.cpp

index b36219f..4844e8a 100755 (executable)
@@ -486,6 +486,7 @@ ActionSet* GroupManager::getActionSetfromString(std::string description)
     char *plainPtr = NULL;
     char *attr = NULL, *desc = NULL;
 
+    Action *action = NULL;
     Capability *capa = NULL;
     ActionSet *actionset = new ActionSet();
 
@@ -540,7 +541,6 @@ ActionSet* GroupManager::getActionSetfromString(std::string description)
 
         if (desc != NULL)
         {
-            Action *action = NULL;
             strcpy(desc, token);
             token = strtok_r(desc, DESC_DELIMITER, &descPtr);
 
@@ -554,7 +554,7 @@ ActionSet* GroupManager::getActionSetfromString(std::string description)
                 token = strtok_r(attr, ATTR_DELIMITER, &attrPtr);
                 while (token != NULL)
                 {
-                    if (strcmp(token, "uri") == 0)
+                    if ( (action == NULL) && strcmp(token, "uri") == 0)    //consider only first "uri" as uri, other as attribute.
                     {
                         token = strtok_r(NULL, ATTR_DELIMITER, &attrPtr);
                         if(token == NULL)
@@ -596,7 +596,10 @@ ActionSet* GroupManager::getActionSetfromString(std::string description)
             }
 
             if( action != NULL )
+            {
                 actionset->listOfAction.push_back(action);
+                action = NULL;
+            }
             else
                 goto exit;
             //delete action;
@@ -616,6 +619,7 @@ ActionSet* GroupManager::getActionSetfromString(std::string description)
     return actionset;
 
 exit:
+    DELETE(action);
     DELETE(capa)
     DELETE(actionset)
     DELETEARRAY(attr);