Skip to content

Commit 5f8a9f0

Browse files
committed
mdns: do not close an fd that is not open
Coverity: CID 739659 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS) At (7): "capturingSkfd" is passed to a parameter that cannot be negative. CID 739660 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS) At (8): "electionSkfd" is passed to a parameter that cannot be negative. CID 739661 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS) At (9): "helloSkfd" is passed to a parameter that cannot be negative. CID 739656 (#6 of 14): Argument cannot be negative (NEGATIVE_RETURNS) At (7): "capturingSkfd" is passed to a parameter that cannot be negative. CID 739656 (#9 of 14): Argument cannot be negative (NEGATIVE_RETURNS) At (7): "electionSkfd" is passed to a parameter that cannot be negative. CID 739656 (#10 of 14): Argument cannot be negative (NEGATIVE_RETURNS) At (7): "helloSkfd" is passed to a parameter that cannot be negative. Signed-off-by: Ferry Huberts <[email protected]>
1 parent fd16a77 commit 5f8a9f0

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

lib/mdns/src/NetworkInterfaces.c

+18-6
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,15 @@ CreateInterface(const char *ifName, struct interface *olsrIntf)
464464
electionSkfd = CreateRouterElectionSocket(ifName);
465465
helloSkfd = CreateHelloSocket(ifName);
466466
if (capturingSkfd < 0 || electionSkfd < 0 || helloSkfd < 0) {
467-
close(capturingSkfd);
468-
close(electionSkfd);
469-
close(helloSkfd);
467+
if (capturingSkfd >= 0) {
468+
close(capturingSkfd);
469+
}
470+
if (electionSkfd >= 0) {
471+
close(electionSkfd);
472+
}
473+
if (helloSkfd >= 0) {
474+
close(helloSkfd);
475+
}
470476
free(newIf);
471477
return 0;
472478
}
@@ -484,9 +490,15 @@ CreateInterface(const char *ifName, struct interface *olsrIntf)
484490
ifr.ifr_name[IFNAMSIZ - 1] = '\0'; /* Ensures null termination */
485491
if (ioctl(ioctlSkfd, SIOCGIFHWADDR, &ifr) < 0) {
486492
BmfPError("ioctl(SIOCGIFHWADDR) error for interface \"%s\"", ifName);
487-
close(capturingSkfd);
488-
close(electionSkfd);
489-
close(helloSkfd);
493+
if (capturingSkfd >= 0) {
494+
close(capturingSkfd);
495+
}
496+
if (electionSkfd >= 0) {
497+
close(electionSkfd);
498+
}
499+
if (helloSkfd >= 0) {
500+
close(helloSkfd);
501+
}
490502
free(newIf);
491503
return 0;
492504
}

0 commit comments

Comments
 (0)