aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/devices
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2021-10-26 16:19:45 +0200
committerDamjan Marion <dmarion@me.com>2021-10-27 20:19:39 +0000
commitc3225ddf8a3db9ee0f0d6edb7d82717d8cf20b36 (patch)
tree695ae2f9608b45ee96aabb7e92f89a8b4859761b /src/vnet/devices
parente2f3aa16e27857929c1a8fbd921426a51ecb5538 (diff)
devices: fix coverity warning/don't leak fd
Move socket creation past code which returns from function to avoid leaking the socket in case of an early error return. Type: fix Signed-off-by: Klement Sekera <ksekera@cisco.com> Change-Id: I9e18bd32022441c17ca920d1c2458b058b76c3c0
Diffstat (limited to 'src/vnet/devices')
-rw-r--r--src/vnet/devices/af_packet/device.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/vnet/devices/af_packet/device.c b/src/vnet/devices/af_packet/device.c
index 8e4bc2b6b7f..c8e59c3566c 100644
--- a/src/vnet/devices/af_packet/device.c
+++ b/src/vnet/devices/af_packet/device.c
@@ -336,7 +336,7 @@ static clib_error_t *af_packet_set_mac_address_function
af_packet_main_t *apm = &af_packet_main;
af_packet_if_t *apif =
pool_elt_at_index (apm->interfaces, hi->dev_instance);
- int rv, fd = socket (AF_UNIX, SOCK_DGRAM, 0);
+ int rv, fd;
struct ifreq ifr;
if (apif->mode == AF_PACKET_IF_MODE_IP)
@@ -347,6 +347,7 @@ static clib_error_t *af_packet_set_mac_address_function
" MAC update failed, interface is in IP mode");
}
+ fd = socket (AF_UNIX, SOCK_DGRAM, 0);
if (0 > fd)
{
vlib_log_warn (apm->log_class, "af_packet_%s could not open socket",