IOT-1302 Thread-unsafe code in oicgroup.c
[platform/upstream/iotivity.git] / service / resource-directory / src / rd_server.c
index c9c72c2..7664c64 100644 (file)
@@ -164,20 +164,24 @@ OCStackResult OCRDStart()
 {
     OCResourceHandle rdHandle = NULL;
 
-    OCStackResult result = OCCreateResource(&rdHandle,
-                                OC_RSRVD_RESOURCE_TYPE_RD,
-                                OC_RSRVD_INTERFACE_DEFAULT,
-                                OC_RSRVD_RD_URI,
-                                rdEntityHandler,
-                                NULL,
-                                (OC_ACTIVE | OC_DISCOVERABLE | OC_OBSERVABLE));
-
+    OCStackResult result = OCRDInitializeStorage();
+    if (result == OC_STACK_OK)
+    {
+        result = OCCreateResource(&rdHandle,
+                                  OC_RSRVD_RESOURCE_TYPE_RD,
+                                  OC_RSRVD_INTERFACE_DEFAULT,
+                                  OC_RSRVD_RD_URI,
+                                  rdEntityHandler,
+                                  NULL,
+                                  (OC_ACTIVE | OC_DISCOVERABLE | OC_OBSERVABLE));
+    }
     if (result == OC_STACK_OK)
     {
         OIC_LOG(DEBUG, TAG, "Resource Directory Started.");
     }
     else
     {
+        OCRDTerminateStorage();
         OIC_LOG(ERROR, TAG, "Failed starting Resource Directory.");
     }
 
@@ -189,6 +193,8 @@ OCStackResult OCRDStart()
  */
 OCStackResult OCRDStop()
 {
+    OCRDTerminateStorage();
+
     OCStackResult result = OCStop();
 
     if (result == OC_STACK_OK)