瀏覽代碼

fix UA_Client_disconnect/close crash (#1562)

* fix UA_Client_disconnect/close SIGSEGV

* add a unit test
StalderT 7 年之前
父節點
當前提交
5508c34f80
共有 2 個文件被更改,包括 12 次插入3 次删除
  1. 3 3
      include/ua_plugin_network.h
  2. 9 0
      tests/client/check_client.c

+ 3 - 3
include/ua_plugin_network.h

@@ -50,12 +50,12 @@ typedef struct {
 } UA_ConnectionConfig;
 
 typedef enum {
+    UA_CONNECTION_CLOSED,      /* The socket has been closed and the connection
+                                * will be deleted */
     UA_CONNECTION_OPENING,     /* The socket is open, but the HEL/ACK handshake
                                 * is not done */
-    UA_CONNECTION_ESTABLISHED, /* The socket is open and the connection
+    UA_CONNECTION_ESTABLISHED  /* The socket is open and the connection
                                 * configured */
-    UA_CONNECTION_CLOSED       /* The socket has been closed and the connection
-                                * will be deleted */
 } UA_ConnectionState;
 
 struct UA_Connection {

+ 9 - 0
tests/client/check_client.c

@@ -216,6 +216,14 @@ START_TEST(Client_activateSessionClose) {
 }
 END_TEST
 
+START_TEST(Client_delete_without_connect) {
+    UA_ClientConfig clientConfig = UA_ClientConfig_default;
+    UA_Client *client = UA_Client_new(clientConfig);
+    ck_assert_msg(client != NULL);
+    UA_Client_delete(client);
+}
+END_TEST
+
 START_TEST(Client_activateSessionTimeout) {
     // restart server
     teardown();
@@ -270,6 +278,7 @@ static Suite* testSuite_Client(void) {
     tcase_add_test(tc_client, Client_connect_username);
     tcase_add_test(tc_client, Client_endpoints);
     tcase_add_test(tc_client, Client_read);
+    tcase_add_test(tc_client, Client_delete_without_connect);
     suite_add_tcase(s,tc_client);
     TCase *tc_client_reconnect = tcase_create("Client Reconnect");
     tcase_add_checked_fixture(tc_client_reconnect, setup, teardown);