af-packet: fix cppcheck false positive

[src/source-af-packet.c:1903]: (error) Resource leak: fd
pull/2644/head
Victor Julien 8 years ago
parent 3726fd66be
commit 6227d0955f

@ -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)

Loading…
Cancel
Save