Browse Source

buffer can be freed on client_disconnect in symmetry with client_connect, relates #343

Stasik0 9 years ago
parent
commit
c82a7cac9f
2 changed files with 14 additions and 5 deletions
  1. 3 0
      examples/client.c
  2. 11 5
      src/client/ua_client.c

+ 3 - 0
examples/client.c

@@ -27,6 +27,9 @@ int main(int argc, char *argv[]) {
         UA_Client_delete(client);
         return retval;
     }
+    UA_Client_disconnect(client);
+    retval = UA_Client_connect(client, ClientNetworkLayerTCP_connect,
+                                             "opc.tcp://localhost:16664");
 
     // Browse some objects
     printf("Browsing nodes in objects folder:\n");

+ 11 - 5
src/client/ua_client.c

@@ -514,11 +514,17 @@ UA_StatusCode UA_Client_connect(UA_Client *client, UA_ConnectClientConnection co
 
 UA_StatusCode UA_Client_disconnect(UA_Client *client) {
     UA_StatusCode retval;
-    if(client->channel.connection->state != UA_CONNECTION_ESTABLISHED)
-        return UA_STATUSCODE_GOOD;
-    retval = CloseSession(client);
-    if(retval == UA_STATUSCODE_GOOD)
-        retval = CloseSecureChannel(client);
+    if(client->channel.connection->state == UA_CONNECTION_ESTABLISHED){
+        retval = CloseSession(client);
+        if(retval == UA_STATUSCODE_GOOD)
+            retval = CloseSecureChannel(client);
+    }
+    UA_Connection* c = client->channel.connection;
+    if(c){
+        UA_Connection_detachSecureChannel(c);
+        if(c->close)
+            c->close(c);
+    }
     return retval;
 }