Skip to content

Commit

Permalink
bmf: do not close an fd that is not open
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
fhuberts committed Oct 23, 2012
1 parent 20faf6d commit 57cdbf6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/bmf/src/NetworkInterfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,9 @@ static int CreateInterface(
capturingSkfd = CreateCaptureSocket(ifName);
if (capturingSkfd < 0)
{
close(encapsulatingSkfd);
if (encapsulatingSkfd >= 0) {
close(encapsulatingSkfd);
}
free(newIf);
return 0;
}
Expand All @@ -1419,7 +1421,9 @@ static int CreateInterface(
listeningSkfd = CreateListeningSocket(ifName);
if (listeningSkfd < 0)
{
close(encapsulatingSkfd); /* no problem if 'encapsulatingSkfd' is -1 */
if (encapsulatingSkfd >= 0) {
close(encapsulatingSkfd); /* no problem if 'encapsulatingSkfd' is -1 */
}
free(newIf);
return 0;
}
Expand All @@ -1438,8 +1442,12 @@ static int CreateInterface(
if (ioctl(ioctlSkfd, SIOCGIFHWADDR, &ifr) < 0)
{
BmfPError("ioctl(SIOCGIFHWADDR) error for interface \"%s\"", ifName);
close(capturingSkfd);
close(encapsulatingSkfd);
if (capturingSkfd >= 0) {
close(capturingSkfd);
}
if (encapsulatingSkfd >= 0) {
close(encapsulatingSkfd);
}
free(newIf);
return 0;
}
Expand Down

0 comments on commit 57cdbf6

Please sign in to comment.