resource: Fix cppcheck issues in resource/csdk/security/ dir
authorRavi Nanjundappa <nravi.n@samsung.com>
Tue, 22 Sep 2015 04:38:19 +0000 (10:08 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Wed, 23 Sep 2015 01:39:31 +0000 (01:39 +0000)
This patch fixes the "(error) Possible null pointer dereference:" issues
reported by cppcheck tool in resource/csdk/security/ directory.

Change-Id: I36c41312fe3d78edd43c6c505b875ecbb6ba0dfa
Signed-off-by: Ravi Nanjundappa <nravi.n@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2905
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
Reviewed-by: Shilpa Sodani <shilpa.a.sodani@intel.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
resource/csdk/security/src/amsmgr.c
resource/csdk/security/src/policyengine.c

index 365cb10b13721e918eeb5c7a57846f85698a5c54..c0f7377f6d5f6a7abc7c34df496276bb9eb67415 100644 (file)
@@ -199,7 +199,8 @@ static OCStackApplicationResult SecurePortDiscoveryCallback(void *ctx, OCDoHandl
     OCResourcePayload* resPayload = ((OCDiscoveryPayload*)clientResponse->payload)->resources;
 
     //Verifying if the ID of the sender is an AMS service that this device trusts.
-    if(memcmp(context->amsMgrContext->amsDeviceId.id, resPayload->sid,
+    if(resPayload &&
+       memcmp(context->amsMgrContext->amsDeviceId.id, resPayload->sid,
                     sizeof(context->amsMgrContext->amsDeviceId.id)) != 0)
     {
         context->retVal = ACCESS_DENIED_AMS_SERVICE_ERROR;
index 3515c0796f2e4861a4da7fb6c5de68a3b7697fc6..196a778f976e525ced698f254b199432142efac7 100644 (file)
@@ -429,9 +429,9 @@ exit:
  */
 OCStackResult InitPolicyEngine(PEContext_t *context)
 {
-    context->amsMgrContext = (AmsMgrContext_t *)OICMalloc(sizeof(AmsMgrContext_t));
     if(NULL != context)
     {
+        context->amsMgrContext = (AmsMgrContext_t *)OICMalloc(sizeof(AmsMgrContext_t));
         SetPolicyEngineState(context, AWAITING_REQUEST);
     }
 
@@ -449,7 +449,7 @@ void DeInitPolicyEngine(PEContext_t *context)
     if(NULL != context)
     {
         SetPolicyEngineState(context, STOPPED);
+        OICFree(context->amsMgrContext);
     }
-    OICFree(context->amsMgrContext);
     return;
 }