From bea9b75fad0e91ebcb6f8606e76407252a380a85 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 21 Apr 2024 15:24:14 +0900 Subject: [PATCH] fixed a file descriptor leak --- lib/gem-nwif.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/gem-nwif.c b/lib/gem-nwif.c index e8dbb2df..773e9932 100644 --- a/lib/gem-nwif.c +++ b/lib/gem-nwif.c @@ -141,7 +141,11 @@ int hawk_gem_bcstrtoifindex (hawk_gem_t* gem, const hawk_bch_t* ptr, unsigned in HAWK_MEMSET (&ifr, 0, HAWK_SIZEOF(ifr)); len = hawk_copy_bcstr(ifr.ifr_name, HAWK_COUNTOF(ifr.ifr_name), ptr); - if (ptr[len] != '\0') return -1; /* name too long */ + if (ptr[len] != '\0') + { + HAWK_CLOSE (h); + return -1; /* name too long */ + } x = ioctl(h, SIOCGIFINDEX, &ifr); HAWK_CLOSE (h); @@ -227,7 +231,11 @@ int hawk_gem_bcharstoifindex (hawk_gem_t* gem, const hawk_bch_t* ptr, hawk_oow_t } HAWK_MEMSET (&ifr, 0, HAWK_SIZEOF(ifr)); - if (hawk_copy_bchars_to_bcstr(ifr.ifr_name, HAWK_COUNTOF(ifr.ifr_name), ptr, len) < len) return -1; /* name too long */ + if (hawk_copy_bchars_to_bcstr(ifr.ifr_name, HAWK_COUNTOF(ifr.ifr_name), ptr, len) < len) + { + HAWK_CLOSE (h); + return -1; /* name too long */ + } x = ioctl(h, SIOCGIFINDEX, &ifr); HAWK_CLOSE (h);