Browse Source

fix(plugin): Fix an edge case memleak during policy startup

Julius Pfrommer 5 years ago
parent
commit
67d3c2c955

+ 7 - 3
plugins/securityPolicies/ua_securitypolicy_basic128rsa15.c

@@ -582,11 +582,11 @@ clear_sp_basic128rsa15(UA_SecurityPolicy *securityPolicy) {
     if(securityPolicy == NULL)
     if(securityPolicy == NULL)
         return;
         return;
 
 
+    UA_ByteString_deleteMembers(&securityPolicy->localCertificate);
+
     if(securityPolicy->policyContext == NULL)
     if(securityPolicy->policyContext == NULL)
         return;
         return;
 
 
-    UA_ByteString_deleteMembers(&securityPolicy->localCertificate);
-
     /* delete all allocated members in the context */
     /* delete all allocated members in the context */
     Basic128Rsa15_PolicyContext *pc = (Basic128Rsa15_PolicyContext *)
     Basic128Rsa15_PolicyContext *pc = (Basic128Rsa15_PolicyContext *)
         securityPolicy->policyContext;
         securityPolicy->policyContext;
@@ -871,7 +871,11 @@ UA_SecurityPolicy_Basic128Rsa15(UA_SecurityPolicy *policy,
     policy->updateCertificateAndPrivateKey = updateCertificateAndPrivateKey_sp_basic128rsa15;
     policy->updateCertificateAndPrivateKey = updateCertificateAndPrivateKey_sp_basic128rsa15;
     policy->clear = clear_sp_basic128rsa15;
     policy->clear = clear_sp_basic128rsa15;
 
 
-    return policyContext_newContext_sp_basic128rsa15(policy, localPrivateKey);
+    UA_StatusCode res = policyContext_newContext_sp_basic128rsa15(policy, localPrivateKey);
+    if(res != UA_STATUSCODE_GOOD)
+        clear_sp_basic128rsa15(policy);
+
+    return res;
 }
 }
 
 
 #endif
 #endif

+ 7 - 3
plugins/securityPolicies/ua_securitypolicy_basic256.c

@@ -530,11 +530,11 @@ clear_sp_basic256(UA_SecurityPolicy *securityPolicy) {
     if(securityPolicy == NULL)
     if(securityPolicy == NULL)
         return;
         return;
 
 
+    UA_ByteString_deleteMembers(&securityPolicy->localCertificate);
+
     if(securityPolicy->policyContext == NULL)
     if(securityPolicy->policyContext == NULL)
         return;
         return;
 
 
-    UA_ByteString_deleteMembers(&securityPolicy->localCertificate);
-
     /* delete all allocated members in the context */
     /* delete all allocated members in the context */
     Basic256_PolicyContext *pc = (Basic256_PolicyContext *)
     Basic256_PolicyContext *pc = (Basic256_PolicyContext *)
         securityPolicy->policyContext;
         securityPolicy->policyContext;
@@ -820,7 +820,11 @@ UA_SecurityPolicy_Basic256(UA_SecurityPolicy *policy,
     policy->updateCertificateAndPrivateKey = updateCertificateAndPrivateKey_sp_basic256;
     policy->updateCertificateAndPrivateKey = updateCertificateAndPrivateKey_sp_basic256;
     policy->clear = clear_sp_basic256;
     policy->clear = clear_sp_basic256;
 
 
-    return policyContext_newContext_sp_basic256(policy, localPrivateKey);
+    UA_StatusCode res = policyContext_newContext_sp_basic256(policy, localPrivateKey);
+    if(res != UA_STATUSCODE_GOOD)
+        clear_sp_basic256(policy);
+
+    return res;
 }
 }
 
 
 #endif
 #endif

+ 7 - 3
plugins/securityPolicies/ua_securitypolicy_basic256sha256.c

@@ -572,11 +572,11 @@ clear_sp_basic256sha256(UA_SecurityPolicy *securityPolicy) {
     if(securityPolicy == NULL)
     if(securityPolicy == NULL)
         return;
         return;
 
 
+    UA_ByteString_deleteMembers(&securityPolicy->localCertificate);
+
     if(securityPolicy->policyContext == NULL)
     if(securityPolicy->policyContext == NULL)
         return;
         return;
 
 
-    UA_ByteString_deleteMembers(&securityPolicy->localCertificate);
-
     /* delete all allocated members in the context */
     /* delete all allocated members in the context */
     Basic256Sha256_PolicyContext *pc = (Basic256Sha256_PolicyContext *)
     Basic256Sha256_PolicyContext *pc = (Basic256Sha256_PolicyContext *)
         securityPolicy->policyContext;
         securityPolicy->policyContext;
@@ -861,7 +861,11 @@ UA_SecurityPolicy_Basic256Sha256(UA_SecurityPolicy *policy,
     policy->updateCertificateAndPrivateKey = updateCertificateAndPrivateKey_sp_basic256sha256;
     policy->updateCertificateAndPrivateKey = updateCertificateAndPrivateKey_sp_basic256sha256;
     policy->clear = clear_sp_basic256sha256;
     policy->clear = clear_sp_basic256sha256;
 
 
-    return policyContext_newContext_sp_basic256sha256(policy, localPrivateKey);
+    UA_StatusCode res = policyContext_newContext_sp_basic256sha256(policy, localPrivateKey);
+    if(res != UA_STATUSCODE_GOOD)
+        clear_sp_basic256sha256(policy);
+
+    return res;
 }
 }
 
 
 #endif
 #endif