Pārlūkot izejas kodu

Initialize new server on every run

Stefan Profanter 7 gadi atpakaļ
vecāks
revīzija
a7d350fa69
1 mainītis faili ar 7 papildinājumiem un 12 dzēšanām
  1. 7 12
      tests/fuzz/fuzz_binary_message.c

+ 7 - 12
tests/fuzz/fuzz_binary_message.c

@@ -5,24 +5,17 @@
 
 #include "fuzz_common.h"
 
-UA_Connection c;
-UA_ServerConfig config;
-UA_Server *server = NULL;
-UA_ByteString msg;
-
 /*
 ** Main entry point.  The fuzzer invokes this function with each
 ** fuzzed input.
 */
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
-    if (server == NULL) {
-        c = createDummyConnection();
-        config = UA_ServerConfig_standard;
-        config.logger = UA_Log_Stdout;
 
-        // no freeing needed, fuzzer is killed or shuts down due to exception
-        server = UA_Server_new(config);
-    }
+    UA_Connection c = createDummyConnection();
+    UA_ServerConfig config = UA_ServerConfig_standard;
+    config.logger = UA_Log_Stdout;
+    UA_Server *server = UA_Server_new(config);
+    UA_ByteString msg;
 
     config.logger = UA_Log_Stdout;
     msg.length = size;
@@ -31,5 +24,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
     UA_StatusCode retval = UA_Connection_completeMessages(&c, &msg, &reallocated);
     if(retval == UA_STATUSCODE_GOOD && msg.length > 0)
         UA_Server_processBinaryMessage(server, &c, &msg);
+    UA_Server_delete(server);
+    UA_Connection_deleteMembers(&c);
     return 0;
 }