(readv): Cope with malloc(0) returning null pointer.
(writev): call write() even when total size is zero.
This commit is contained in:
parent
c2cf7ddd2c
commit
71485ac5a0
1 changed files with 3 additions and 7 deletions
|
@ -271,8 +271,7 @@ posix_setsockopt(int fd, int level, int optname,
|
||||||
const void *optval, socklen_t optlen)
|
const void *optval, socklen_t optlen)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* SO_REUSEADDR requests from tcp_listen.c
|
* SO_REUSEADDR requests to permit another bind even when the
|
||||||
* to permit another bind even when the
|
|
||||||
* port is still in state TIME_WAIT. Windows' SO_REUSEADDR is
|
* port is still in state TIME_WAIT. Windows' SO_REUSEADDR is
|
||||||
* broken: it makes bind() succeed no matter what, even if
|
* broken: it makes bind() succeed no matter what, even if
|
||||||
* there's another server running on the same port. Luckily,
|
* there's another server running on the same port. Luckily,
|
||||||
|
@ -507,7 +506,7 @@ readv(int fd, const struct iovec *iov, int iovcnt)
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = malloc(total_bytes);
|
buffer = malloc(total_bytes);
|
||||||
if (buffer == NULL)
|
if (buffer == NULL && total_bytes != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
bytes_read = posix_read(fd, buffer, total_bytes);
|
bytes_read = posix_read(fd, buffer, total_bytes);
|
||||||
|
@ -559,11 +558,8 @@ writev(int fd, const struct iovec *iov, int iovcnt)
|
||||||
for (i = 0; i < iovcnt; i++)
|
for (i = 0; i < iovcnt; i++)
|
||||||
total_bytes += iov[i].iov_len;
|
total_bytes += iov[i].iov_len;
|
||||||
|
|
||||||
if (total_bytes == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
buffer = malloc(total_bytes);
|
buffer = malloc(total_bytes);
|
||||||
if (buffer == NULL)
|
if (buffer == NULL && total_bytes != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
buffer_location = buffer;
|
buffer_location = buffer;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue