p2pd: do not close an fd that is not open
authorFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 23 Oct 2012 10:12:46 +0000 (12:12 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 23 Oct 2012 11:45:14 +0000 (13:45 +0200)
Coverity:
CID 739656 (#6 of 8): Argument cannot be negative (NEGATIVE_RETURNS)
At (7): "capturingSkfd" is passed to a parameter that cannot be negative.

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/p2pd/src/NetworkInterfaces.c

index a224462..f371bc0 100644 (file)
@@ -213,7 +213,9 @@ CreateInterface(const char *ifName, struct interface *olsrIntf)
   ifr.ifr_name[IFNAMSIZ - 1] = '\0';    /* Ensures null termination */
   if (ioctl(ioctlSkfd, SIOCGIFHWADDR, &ifr) < 0) {
     P2pdPError("ioctl(SIOCGIFHWADDR) error for interface \"%s\"", ifName);
-    close(capturingSkfd);
+    if (capturingSkfd >= 0) {
+      close(capturingSkfd);
+    }
     free(newIf);
     return 0;
   }