Make device close cleaner.
authorEtienne Dechamps <etienne@edechamps.fr>
Sun, 22 Jun 2014 08:53:26 +0000 (09:53 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Sun, 22 Jun 2014 12:01:30 +0000 (14:01 +0200)
src/bsd/device.c
src/cygwin/device.c
src/linux/device.c
src/mingw/device.c
src/multicast_device.c
src/raw_socket_device.c
src/solaris/device.c
src/uml_device.c
src/vde_device.c

index 145b79e5abe811440e9eda88f3022d67330b477d..49508bc53432411d847ab96453b162411cad00f0 100644 (file)
@@ -197,9 +197,11 @@ static void close_device(void) {
                default:
                        close(device_fd);
        }
+       device_fd = -1;
 
-       free(device);
-       free(iface);
+       free(device); device = NULL;
+       free(iface); iface = NULL;
+       device_info = NULL;
 }
 
 static bool read_packet(vpn_packet_t *packet) {
index a110f7f2bc0e9600bf75a3a5cc495b941fa5fff1..d522b4f4ac35c6e8e0a25b4ba6786c9bebb72b09 100644 (file)
@@ -215,12 +215,13 @@ static bool setup_device(void) {
 static void close_device(void) {
        close(sp[0]);
        close(sp[1]);
-       CloseHandle(device_handle);
+       CloseHandle(device_handle); device_handle = INVALID_HANDLE_VALUE;
 
        kill(reader_pid, SIGKILL);
 
-       free(device);
-       free(iface);
+       free(device); device = NULL;
+       free(iface); iface = NULL;
+       device_info = NULL;
 }
 
 static bool read_packet(vpn_packet_t *packet) {
index 6ed1622c08a5f1442174f459e07db4351f93fcdd..cfd99ff4a3f9ff269b4d849c6b75432d7346522c 100644 (file)
@@ -110,10 +110,12 @@ static bool setup_device(void) {
 
 static void close_device(void) {
        close(device_fd);
+       device_fd = -1;
 
-       free(type);
-       free(device);
-       free(iface);
+       free(type); type = NULL;
+       free(device); device = NULL;
+       free(iface); iface = NULL;
+       device_info = NULL;
 }
 
 static bool read_packet(vpn_packet_t *packet) {
index 0642725fa5247b9440967ac788e68fd45d5ba407..85c0c7b1475744a0a9ff0483b9f1419140bfe865 100644 (file)
@@ -213,10 +213,11 @@ static bool setup_device(void) {
 }
 
 static void close_device(void) {
-       CloseHandle(device_handle);
+       CloseHandle(device_handle); device_handle = INVALID_HANDLE_VALUE;
 
-       free(device);
-       free(iface);
+       free(device); device = NULL;
+       free(iface); iface = NULL;
+       device_info = NULL;
 }
 
 static bool read_packet(vpn_packet_t *packet) {
index 48e120038236055db48b2777181a72b441704dc1..ba272eb20eb5a6bd68dd6b010944ecfd2136db07 100644 (file)
@@ -148,13 +148,15 @@ error:
 }
 
 static void close_device(void) {
-       close(device_fd);
+       close(device_fd); device_fd = -1;
 
-       free(device);
-       free(iface);
+       free(device); device = NULL;
+       free(iface); iface = NULL;
 
-       if(ai)
-               freeaddrinfo(ai);
+       if(ai) {
+               freeaddrinfo(ai); ai = NULL;
+       }
+       device_info = NULL;
 }
 
 static bool read_packet(vpn_packet_t *packet) {
index 57df5b7a0ee25a9a616ea9160db31a812a5ec9ed..a8c2c861001e29a3b7f5aa49c1b2e528b11882ac 100644 (file)
@@ -83,10 +83,11 @@ static bool setup_device(void) {
 }
 
 static void close_device(void) {
-       close(device_fd);
+       close(device_fd); device_fd = -1;
 
-       free(device);
-       free(iface);
+       free(device); device = NULL;
+       free(iface); iface = NULL;
+       device_info = NULL;
 }
 
 static bool read_packet(vpn_packet_t *packet) {
index c11f60f70da3d7eb9c1ca88d81ccb9fe64035986..a4c0d27e902d373ee4c9fcacc0442d48393e8c75 100644 (file)
@@ -287,11 +287,11 @@ static void close_device(void) {
                }
        }
 
-       close(ip_fd);
-       close(device_fd);
+       close(ip_fd); ip_fd = -1;
+       close(device_fd); device_fd = -1;
 
-       free(device);
-       free(iface);
+       free(device); device = NULL;
+       free(iface); iface = NULL;
 }
 
 static bool read_packet(vpn_packet_t *packet) {
index 5193fe98abcd5251d876c64f473d79d995a92114..f2b52cbbc2c9c912762d009ba942bc7067d1fdb2 100644 (file)
@@ -156,22 +156,29 @@ static bool setup_device(void) {
 }
 
 void close_device(void) {
-       if(listen_fd >= 0)
-               close(listen_fd);
+       if(listen_fd >= 0) {
+               close(listen_fd); listen_fd = -1;
+       }
 
-       if(request_fd >= 0)
-               close(request_fd);
+       if(request_fd >= 0) {
+               close(request_fd); request_fd = -1;
+       }
 
-       if(data_fd >= 0)
-               close(data_fd);
+       if(data_fd >= 0) {
+               close(data_fd); data_fd = -1;
+       }
 
-       if(write_fd >= 0)
-               close(write_fd);
+       if(write_fd >= 0) {
+               close(write_fd); write_fd = -1;
+       }
 
        unlink(device);
 
-       free(device);
-       if(iface) free(iface);
+       free(device); device = NULL;
+       if(iface) {
+               free(iface); iface = NULL;
+       }
+       device_info = NULL;
 }
 
 static bool read_packet(vpn_packet_t *packet) {
index 1021f5d34cee34269c6ce4bdde268b858a97008f..55d66b469ea6f4cbf0d1ee5472610a7c0a46c222 100644 (file)
@@ -82,15 +82,18 @@ static bool setup_device(void) {
 }
 
 static void close_device(void) {
-       if(conn)
-               plug.vde_close(conn);
+       if(conn) {
+               plug.vde_close(conn); conn = NULL;
+       }
 
        if(plug.dl_handle)
                libvdeplug_dynclose(plug);
 
-       free(device);
+       free(device); device = NULL;
+
+       free(iface); iface = NULL;
 
-       free(iface);
+       device_info = NULL;
 }
 
 static bool read_packet(vpn_packet_t *packet) {