From 57cdbf687a863f3fcf0750a86c8579aa4a312382 Mon Sep 17 00:00:00 2001 From: Ferry Huberts Date: Tue, 23 Oct 2012 13:03:07 +0200 Subject: [PATCH] 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 --- lib/bmf/src/NetworkInterfaces.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/bmf/src/NetworkInterfaces.c b/lib/bmf/src/NetworkInterfaces.c index 9c69bab0..61ecedad 100644 --- a/lib/bmf/src/NetworkInterfaces.c +++ b/lib/bmf/src/NetworkInterfaces.c @@ -1404,7 +1404,9 @@ static int CreateInterface( capturingSkfd = CreateCaptureSocket(ifName); if (capturingSkfd < 0) { - close(encapsulatingSkfd); + if (encapsulatingSkfd >= 0) { + close(encapsulatingSkfd); + } free(newIf); return 0; } @@ -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; } @@ -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; }