浏览代码

fix loadFile when alloc error (#1525)

* fix loadFile when alloc error

* fix loadFile when alloc error (basic128rsa15)
StalderT 6 年之前
父节点
当前提交
dedff4d9d6
共有 2 个文件被更改,包括 4 次插入0 次删除
  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);