bug fix about related memory and security resource.
authorjaesick.shin <jaesick.shin@samsung.com>
Wed, 14 Dec 2016 08:30:55 +0000 (17:30 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 15 Dec 2016 05:23:59 +0000 (05:23 +0000)
1. I did not copy the memory,
   but I freed the memory while I was using it.
2. The initial value of the securityResource variable
   used by the provider was wrong.

second patch include,
1. change OICCalloc to OICMalloc.
2. removed the initialization code from the previous commit,
   so added it again.

Change-Id: I189eb720785a74e39955640484e795170be3b010
Signed-off-by: jaesick.shin <jaesick.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/15593
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification/src/common/NSUtil.c
service/notification/src/provider/NSProviderSubscription.c
service/notification/src/provider/NSProviderSystem.c

index 9bcf11e..0aeb489 100755 (executable)
@@ -29,10 +29,13 @@ OCEntityHandlerRequest *NSCopyOCEntityHandlerRequest(OCEntityHandlerRequest *ent
 
     if (copyOfRequest)
     {
-        // Do shallow copy
         memcpy(copyOfRequest, entityHandlerRequest, sizeof(OCEntityHandlerRequest));
+        copyOfRequest->payload = NULL;
+        copyOfRequest->query = NULL;
+        copyOfRequest->numRcvdVendorSpecificHeaderOptions = 0;
+        copyOfRequest->rcvdVendorSpecificHeaderOptions = NULL;
 
-        if (copyOfRequest->query)
+        if (entityHandlerRequest->query)
         {
             copyOfRequest->query = OICStrdup(entityHandlerRequest->query);
             if (!copyOfRequest->query)
@@ -48,10 +51,6 @@ OCEntityHandlerRequest *NSCopyOCEntityHandlerRequest(OCEntityHandlerRequest *ent
             copyOfRequest->payload = (OCPayload *)
                     (OCRepPayloadClone ((OCRepPayload*) entityHandlerRequest->payload));
         }
-
-        // Ignore vendor specific header options for example
-        copyOfRequest->numRcvdVendorSpecificHeaderOptions = 0;
-        copyOfRequest->rcvdVendorSpecificHeaderOptions = NULL;
     }
 
     if (copyOfRequest)
index d2563ce..12ef5d1 100644 (file)
@@ -183,7 +183,7 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour
         }\r
 \r
         bool currPolicy = NSGetPolicy();\r
-        NSAskAcceptanceToUser(entityHandlerRequest);\r
+        NSAskAcceptanceToUser(NSCopyOCEntityHandlerRequest(entityHandlerRequest));\r
 \r
         if (currPolicy == NS_POLICY_PROVIDER)\r
         {\r
@@ -194,6 +194,8 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour
             NS_LOG(DEBUG, "NSGetSubscriptionAccepter == NS_ACCEPTER_CONSUMER");\r
             NSSendConsumerSubResponse(NSCopyOCEntityHandlerRequest(entityHandlerRequest));\r
         }\r
+\r
+        NSFreeOCEntityHandlerRequest(entityHandlerRequest);\r
     }\r
     else if (resourceType == NS_RESOURCE_SYNC)\r
     {\r
index 089a5b7..8ebf078 100644 (file)
@@ -32,7 +32,7 @@ static NSConnectionState NSProviderConnectionState;
 \r
 NSProviderInfo * providerInfo;\r
 bool NSPolicy = true;\r
-bool NSResourceSecurity = true;\r
+bool NSResourceSecurity = false;\r
 \r
 void NSSetProviderConnectionState(NSConnectionState state)\r
 {\r