]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
af-packet: fix cppcheck false positive 2644/head
authorVictor Julien <victor@inliniac.net>
Mon, 3 Apr 2017 14:09:18 +0000 (16:09 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 4 Apr 2017 10:27:23 +0000 (12:27 +0200)
[src/source-af-packet.c:1903]: (error) Resource leak: fd

src/source-af-packet.c

index 1e25d316bb343b14ad6ba4b081cc1db82cf0df76..2f3191620808de4d87c3e316890af608644c3c45 100644 (file)
@@ -1886,21 +1886,23 @@ int AFPIsFanoutSupported(void)
 {
 #ifdef HAVE_PACKET_FANOUT
     int fd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
-    if (fd != -1) {
-        uint16_t mode = PACKET_FANOUT_HASH | PACKET_FANOUT_FLAG_DEFRAG;
-        uint16_t id = 1;
-        uint32_t option = (mode << 16) | (id & 0xffff);
-        int r = setsockopt(fd, SOL_PACKET, PACKET_FANOUT,(void *)&option, sizeof(option));
-        close(fd);
+    if (fd < 0)
+        return 0;
 
-        if (r < 0) {
-            SCLogPerf("fanout not supported by kernel: %s", strerror(errno));
-            return 0;
-        }
-        return 1;
+    uint16_t mode = PACKET_FANOUT_HASH | PACKET_FANOUT_FLAG_DEFRAG;
+    uint16_t id = 1;
+    uint32_t option = (mode << 16) | (id & 0xffff);
+    int r = setsockopt(fd, SOL_PACKET, PACKET_FANOUT,(void *)&option, sizeof(option));
+    close(fd);
+
+    if (r < 0) {
+        SCLogPerf("fanout not supported by kernel: %s", strerror(errno));
+        return 0;
     }
-#endif
+    return 1;
+#else
     return 0;
+#endif
 }
 
 static int AFPCreateSocket(AFPThreadVars *ptv, char *devname, int verbose)