Fix potential memory leak on Windows
authorJoseph C. Lehner <joseph.c.lehner@gmail.com>
Sat, 19 Nov 2016 19:19:45 +0000 (20:19 +0100)
committerJoseph C. Lehner <joseph.c.lehner@gmail.com>
Sat, 19 Nov 2016 19:19:45 +0000 (20:19 +0100)
ethsock.c

index d086e03da59b0a3ae669a3faeea8a39d86299cc4..3219a0dfa20085b05b4f2d8fc6e45fc48c819ae0 100644 (file)
--- a/ethsock.c
+++ b/ethsock.c
@@ -276,12 +276,6 @@ struct ethsock *ethsock_create(const char *intf, uint16_t protocol)
        struct ethsock *sock;
        int err;
 
-       sock = malloc(sizeof(struct ethsock));
-       if (!sock) {
-               perror("malloc");
-               return NULL;
-       }
-
 #ifdef NMRPFLASH_WINDOWS
        intf = intf_alias_to_wpcap(intf);
        if (!intf) {
@@ -289,6 +283,12 @@ struct ethsock *ethsock_create(const char *intf, uint16_t protocol)
        }
 #endif
 
+       sock = malloc(sizeof(struct ethsock));
+       if (!sock) {
+               perror("malloc");
+               return NULL;
+       }
+
        buf[0] = '\0';
 
        sock->intf = intf;