Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

porting:solve cid38603 issue #2959

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions cfgmgr/teammgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include <sys/stat.h>
#include <signal.h>

#if 1 /* CID-38603: resource leak fd, CP, 2020/11/13 15:02:59 */
#include <unistd.h>
#endif

using namespace std;
using namespace swss;
Expand Down Expand Up @@ -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);

Expand Down