Ver código fonte

fix loadFile when alloc error (#1525)

* fix loadFile when alloc error

* fix loadFile when alloc error (basic128rsa15)
StalderT 6 anos atrás
pai
commit
dedff4d9d6
2 arquivos alterados com 4 adições e 0 exclusões
  1. 2 0
      examples/encryption/server_basic128rsa15.c
  2. 2 0
      examples/server.c

+ 2 - 0
examples/encryption/server_basic128rsa15.c

@@ -26,6 +26,8 @@ static UA_ByteString loadFile(const char *const path) {
         size_t read = fread(fileContents.data, sizeof(UA_Byte), fileContents.length, fp);
         if(read != fileContents.length)
             UA_ByteString_deleteMembers(&fileContents);
+    } else {
+        fileContents.length = 0;
     }
     fclose(fp);
 

+ 2 - 0
examples/server.c

@@ -40,6 +40,8 @@ loadFile(const char *const path) {
         size_t read = fread(fileContents.data, sizeof(UA_Byte), fileContents.length, fp);
         if(read != fileContents.length)
             UA_ByteString_deleteMembers(&fileContents);
+    } else {
+        fileContents.length = 0;
     }
     fclose(fp);