From 0055a14985eb1a388f54add9f67da4208ffd6c56 Mon Sep 17 00:00:00 2001 From: InspurSDN Date: Thu, 16 Nov 2023 15:52:23 +0800 Subject: [PATCH] porting:solve cid38603 issue Description: porting:solve cid38603 issue --- cfgmgr/teammgr.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cfgmgr/teammgr.cpp b/cfgmgr/teammgr.cpp index 40eca9d921..b65cc5f7fa 100644 --- a/cfgmgr/teammgr.cpp +++ b/cfgmgr/teammgr.cpp @@ -18,6 +18,9 @@ #include #include +#if 1 /* CID-38603: resource leak fd, CP, 2020/11/13 15:02:59 */ +#include +#endif using namespace std; using namespace swss; @@ -391,11 +394,36 @@ bool TeamMgr::checkPortIffUp(const string &port) ifr.ifr_name[strlen(port.c_str())] = 0; int fd = socket(AF_UNIX, SOCK_DGRAM, 0); + +#if 1 /* CID-38603: resource leak fd, CP, 2020/11/13 15:02:59 */ + + if (fd == -1) + { + SWSS_LOG_ERROR("failed to create socket"); + return false; + } + + // get port status + int rv = ioctl(fd, SIOCGIFFLAGS, &ifr); + + // close socket + close(fd); + + // failed to get port status + if (rv == -1) + { + SWSS_LOG_ERROR("Failed to get port %s flags", port.c_str()); + return false; + } + +#else /* CID-38603: resource leak fd, CP, 2020/11/13 15:02:59 */ + if (fd == -1 || ioctl(fd, SIOCGIFFLAGS, &ifr) == -1) { SWSS_LOG_ERROR("Failed to get port %s flags", port.c_str()); return false; } +#endif /* CID-38603: resource leak fd, CP, 2020/11/13 15:02:59 */ SWSS_LOG_INFO("Get port %s flags %i", port.c_str(), ifr.ifr_flags);