Browse Source

Now only calling UA_NodeStore_get() once and releasing the node on a successfull search.

ichrispa 9 years ago
parent
commit
433b81b513
1 changed files with 5 additions and 2 deletions
  1. 5 2
      src/server/ua_services_subscription.c

+ 5 - 2
src/server/ua_services_subscription.c

@@ -76,7 +76,9 @@ void Service_CreateMonitoredItems(UA_Server *server, UA_Session *session,
         thisItemsResult->filterResult.encoding = UA_EXTENSIONOBJECT_ENCODINGMASK_NOBODYISENCODED;
         thisItemsResult->filterResult.body     = UA_BYTESTRING_NULL;
         
-        if (UA_NodeStore_get(server->nodestore, (const UA_NodeId *) &(thisItemsRequest->itemToMonitor.nodeId)) == UA_NULL) {
+        const UA_Node *target;
+        target = UA_NodeStore_get(server->nodestore, (const UA_NodeId *) &(thisItemsRequest->itemToMonitor.nodeId));
+        if (target == NULL) {
             thisItemsResult->statusCode = UA_STATUSCODE_BADNODEIDINVALID;
             thisItemsResult->monitoredItemId = 0;
             thisItemsResult->revisedSamplingInterval = 0;
@@ -86,7 +88,7 @@ void Service_CreateMonitoredItems(UA_Server *server, UA_Session *session,
             thisItemsResult->statusCode = UA_STATUSCODE_GOOD;
             
             newMon = UA_MonitoredItem_new();
-            newMon->monitoredNode = UA_NodeStore_get(server->nodestore, (const UA_NodeId *) &(thisItemsRequest->itemToMonitor.nodeId));
+            newMon->monitoredNode = target;
             UA_NodeId_copy(&(newMon->monitoredNode->nodeId), &(newMon->monitoredNodeId));
             newMon->ItemId = ++(session->subscriptionManager.LastSessionID);
             thisItemsResult->monitoredItemId = newMon->ItemId;
@@ -104,6 +106,7 @@ void Service_CreateMonitoredItems(UA_Server *server, UA_Session *session,
             newMon->DiscardOldest = thisItemsRequest->requestedParameters.discardOldest;
             
             LIST_INSERT_HEAD(&sub->MonitoredItems, newMon, listEntry);
+            UA_NodeStore_release(target);
         }
     }
 }