Browse Source

rmeove certificate leaks

Stasik0 10 years ago
parent
commit
f1ce7710ac
3 changed files with 10 additions and 4 deletions
  1. 4 2
      examples/server.c
  2. 3 1
      examples/server_simple.c
  3. 3 1
      src/server/ua_server.c

+ 4 - 2
examples/server.c

@@ -160,7 +160,7 @@ static void stopHandler(int sign) {
 }
 
 static UA_ByteString loadCertificate(void) {
-    UA_ByteString certificate = UA_STRING_NULL;
+	UA_ByteString certificate = UA_STRING_NULL;
 	FILE *fp = NULL;
 	//FIXME: a potiential bug of locating the certificate, we need to get the path from the server's config
 	fp=fopen("localhost.der", "rb");
@@ -193,7 +193,9 @@ int main(int argc, char** argv) {
 	UA_Server *server = UA_Server_new();
 	logger = Logger_Stdout_new();
 	UA_Server_setLogger(server, logger);
-	UA_Server_setServerCertificate(server, loadCertificate());
+    UA_ByteString certificate = loadCertificate();
+    UA_Server_setServerCertificate(server, certificate);
+    UA_ByteString_deleteMembers(&certificate);
 	UA_Server_addNetworkLayer(server, ServerNetworkLayerTCP_new(UA_ConnectionConfig_standard, 16664));
 
 	// print the status every 2 sec

+ 3 - 1
examples/server_simple.c

@@ -62,7 +62,9 @@ int main(int argc, char** argv) {
 	UA_Server *server = UA_Server_new();
     logger = Logger_Stdout_new();
     UA_Server_setLogger(server, logger);
-    UA_Server_setServerCertificate(server, loadCertificate());
+    UA_ByteString certificate = loadCertificate();
+    UA_Server_setServerCertificate(server, certificate);
+    UA_ByteString_deleteMembers(&certificate);
     UA_Server_addNetworkLayer(server, ServerNetworkLayerTCP_new(UA_ConnectionConfig_standard, 16664));
 
     UA_WorkItem work = {.type = UA_WORKITEMTYPE_METHODCALL, .work.methodCall = {.method = testCallback, .data = NULL} };

+ 3 - 1
src/server/ua_server.c

@@ -223,12 +223,14 @@ UA_Server * UA_Server_new(void) {
     server->externalNamespacesSize = 0;
     server->externalNamespaces = UA_NULL;
 
+    server->endpointDescriptions = UA_NULL;
+    server->endpointDescriptionsSize = 0;
+
     UA_EndpointDescription *endpoint = UA_EndpointDescription_new(); // todo: check return code
     if(endpoint) {
         endpoint->securityMode = UA_MESSAGESECURITYMODE_NONE;
         endpoint->securityPolicyUri = UA_STRING_ALLOC("http://opcfoundation.org/UA/SecurityPolicy#None");
         endpoint->transportProfileUri = UA_STRING_ALLOC("http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary");
-        endpoint->userIdentityTokens = UA_malloc(sizeof(UA_UserTokenPolicy));
         if(!endpoint->userIdentityTokens) {
             UA_EndpointDescription_delete(endpoint);
         } else {