Fix a few small memory leaks.
[oweals/tinc.git] / src / uml_socket / device.c
index 3523f6471f277521cfd3966d144ef4e0f3bae5f6..a371e7b439eb1cb1efb0b8199aef2291054032f0 100644 (file)
 #include <sys/un.h>
 
 #include "conf.h"
+#include "device.h"
 #include "net.h"
 #include "logger.h"
 #include "utils.h"
 #include "route.h"
+#include "xalloc.h"
 
 int device_fd = -1;
 static int listen_fd = -1;
@@ -39,10 +41,10 @@ char *iface = NULL;
 static char *device_info;
 
 extern char *identname;
-extern bool running;
+extern volatile bool running;
 
-static int device_total_in = 0;
-static int device_total_out = 0;
+static uint64_t device_total_in = 0;
+static uint64_t device_total_out = 0;
 
 enum request_type { REQ_NEW_CONTROL };
 
@@ -174,7 +176,7 @@ bool read_packet(vpn_packet_t *packet) {
        switch(state) {
                case 0: {
                        struct sockaddr sa;
-                       int salen = sizeof sa;
+                       socklen_t salen = sizeof sa;
 
                        request_fd = accept(listen_fd, &sa, &salen);
                        if(request_fd < 0) {
@@ -243,6 +245,10 @@ bool read_packet(vpn_packet_t *packet) {
 
                        return true;
                }
+
+               default:
+                       logger(LOG_ERR, "Invalid value for state variable in " __FILE__);
+                       abort();
        }
 }
 
@@ -272,6 +278,6 @@ bool write_packet(vpn_packet_t *packet) {
 
 void dump_device_stats(void) {
        logger(LOG_DEBUG, "Statistics for %s %s:", device_info, device);
-       logger(LOG_DEBUG, " total bytes in:  %10d", device_total_in);
-       logger(LOG_DEBUG, " total bytes out: %10d", device_total_out);
+       logger(LOG_DEBUG, " total bytes in:  %10"PRIu64, device_total_in);
+       logger(LOG_DEBUG, " total bytes out: %10"PRIu64, device_total_out);
 }