ss: Close file descriptors in tcp_show_netlink.

ss: Close file descriptors in tcp_show_netlink.

Signed-off-by: Matt Tierney <tierney@cs.nyu.edu>
This commit is contained in:
Matt Tierney 2012-02-15 18:20:38 -05:00 committed by Stephen Hemminger
parent 20ed7b24df
commit c51577cd13
1 changed files with 9 additions and 2 deletions

View File

@ -1563,6 +1563,7 @@ static int tcp_show_netlink(struct filter *f, FILE *dump_fp, int socktype)
} }
if (status == 0) { if (status == 0) {
fprintf(stderr, "EOF on netlink\n"); fprintf(stderr, "EOF on netlink\n");
close(fd);
return 0; return 0;
} }
@ -1578,8 +1579,10 @@ static int tcp_show_netlink(struct filter *f, FILE *dump_fp, int socktype)
h->nlmsg_seq != 123456) h->nlmsg_seq != 123456)
goto skip_it; goto skip_it;
if (h->nlmsg_type == NLMSG_DONE) if (h->nlmsg_type == NLMSG_DONE) {
close(fd);
return 0; return 0;
}
if (h->nlmsg_type == NLMSG_ERROR) { if (h->nlmsg_type == NLMSG_ERROR) {
struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h);
if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) { if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) {
@ -1588,6 +1591,7 @@ static int tcp_show_netlink(struct filter *f, FILE *dump_fp, int socktype)
errno = -err->error; errno = -err->error;
perror("TCPDIAG answers"); perror("TCPDIAG answers");
} }
close(fd);
return 0; return 0;
} }
if (!dump_fp) { if (!dump_fp) {
@ -1596,8 +1600,10 @@ static int tcp_show_netlink(struct filter *f, FILE *dump_fp, int socktype)
continue; continue;
} }
err = tcp_show_sock(h, NULL); err = tcp_show_sock(h, NULL);
if (err < 0) if (err < 0) {
close(fd);
return err; return err;
}
} }
skip_it: skip_it:
@ -1612,6 +1618,7 @@ skip_it:
exit(1); exit(1);
} }
} }
close(fd);
return 0; return 0;
} }