diff options
Diffstat (limited to 'ext/socket')
-rw-r--r-- | ext/socket/ancdata.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c index 89a8921414..61e0576e6b 100644 --- a/ext/socket/ancdata.c +++ b/ext/socket/ancdata.c @@ -1384,8 +1384,16 @@ discard_cmsg(struct cmsghdr *cmh, char *msg_end) int *end = (int *)((char *)cmh + cmh->cmsg_len); while ((char *)fdp + sizeof(int) <= (char *)end && (char *)fdp + sizeof(int) <= msg_end) { - rb_update_max_fd(*fdp); - close(*fdp); + /* + * xxx: nagachika said *fdp can be invalid fd on MacOS X Lion. + * This workaround using fstat is clearly wrong. + * we should investigate why *fdp contains invalid fd. + */ + struct stat buf; + if (fstat(*fdp, &buf) == 0) { + rb_update_max_fd(*fdp); + close(*fdp); + } fdp++; } } |