Browse Source

refactor(server): Simplify the generation of event identifiers

Julius Pfrommer 5 years ago
parent
commit
eca2d4faa2
1 changed files with 3 additions and 5 deletions
  1. 3 5
      src/server/ua_subscription_events.c

+ 3 - 5
src/server/ua_subscription_events.c

@@ -42,11 +42,9 @@ UA_MonitoredItem_removeNodeEventCallback(UA_Server *server, UA_Session *session,
 /* We use a 16-Byte ByteString as an identifier */
 static UA_StatusCode
 generateEventId(UA_ByteString *generatedId) {
-    generatedId->data = (UA_Byte *) UA_malloc(16 * sizeof(UA_Byte));
-    if(!generatedId->data)
-        return UA_STATUSCODE_BADOUTOFMEMORY;
-    generatedId->length = 16;
-
+    UA_StatusCode res = UA_ByteString_allocBuffer(generatedId, 16 * sizeof(UA_Byte));
+    if(res != UA_STATUSCODE_GOOD)
+        return res;
     UA_UInt32 *ids = (UA_UInt32*)generatedId->data;
     ids[0] = UA_UInt32_random();
     ids[1] = UA_UInt32_random();