Skip to content

Commit 57cdbf6

Browse files
committedOct 23, 2012
bmf: do not close an fd that is not open
CID 739656 (#1 of 4): Argument cannot be negative (NEGATIVE_RETURNS) At (7): "encapsulatingSkfd" is passed to a parameter that cannot be negative. CID 739656 (#2 of 4): Argument cannot be negative (NEGATIVE_RETURNS) At (9): "encapsulatingSkfd" is passed to a parameter that cannot be negative. CID 739656 (#3 of 4): Argument cannot be negative (NEGATIVE_RETURNS) At (12): "capturingSkfd" is passed to a parameter that cannot be negative. CID 739656 (#4 of 4): Argument cannot be negative (NEGATIVE_RETURNS) At (11): "encapsulatingSkfd" is passed to a parameter that cannot be negative. Signed-off-by: Ferry Huberts <[email protected]>
1 parent 20faf6d commit 57cdbf6

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed
 

‎lib/bmf/src/NetworkInterfaces.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,9 @@ static int CreateInterface(
14041404
capturingSkfd = CreateCaptureSocket(ifName);
14051405
if (capturingSkfd < 0)
14061406
{
1407-
close(encapsulatingSkfd);
1407+
if (encapsulatingSkfd >= 0) {
1408+
close(encapsulatingSkfd);
1409+
}
14081410
free(newIf);
14091411
return 0;
14101412
}
@@ -1419,7 +1421,9 @@ static int CreateInterface(
14191421
listeningSkfd = CreateListeningSocket(ifName);
14201422
if (listeningSkfd < 0)
14211423
{
1422-
close(encapsulatingSkfd); /* no problem if 'encapsulatingSkfd' is -1 */
1424+
if (encapsulatingSkfd >= 0) {
1425+
close(encapsulatingSkfd); /* no problem if 'encapsulatingSkfd' is -1 */
1426+
}
14231427
free(newIf);
14241428
return 0;
14251429
}
@@ -1438,8 +1442,12 @@ static int CreateInterface(
14381442
if (ioctl(ioctlSkfd, SIOCGIFHWADDR, &ifr) < 0)
14391443
{
14401444
BmfPError("ioctl(SIOCGIFHWADDR) error for interface \"%s\"", ifName);
1441-
close(capturingSkfd);
1442-
close(encapsulatingSkfd);
1445+
if (capturingSkfd >= 0) {
1446+
close(capturingSkfd);
1447+
}
1448+
if (encapsulatingSkfd >= 0) {
1449+
close(encapsulatingSkfd);
1450+
}
14431451
free(newIf);
14441452
return 0;
14451453
}

0 commit comments

Comments
 (0)
Please sign in to comment.