mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-08 17:42:12 +03:00
hurd: writev: Add back cleanup handler
There is a potential memory leak for large writes due to writev being a
"shall occur" cancellation point. Add back the cleanup handler removed
in cf30aa43a5
.
Checked on i686-gnu and x86_64-linux-gnu.
Message-Id: <20230619143842.2901522-1-josimmon@redhat.com>
This commit is contained in:
committed by
Samuel Thibault
parent
4290aed051
commit
c6957bddb9
@@ -26,6 +26,12 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
ifree (struct scratch_buffer *sbuf)
|
||||||
|
{
|
||||||
|
scratch_buffer_free (sbuf);
|
||||||
|
}
|
||||||
|
|
||||||
/* Write data pointed by the buffers described by VECTOR, which
|
/* Write data pointed by the buffers described by VECTOR, which
|
||||||
is a vector of COUNT 'struct iovec's, to file descriptor FD.
|
is a vector of COUNT 'struct iovec's, to file descriptor FD.
|
||||||
The data is written in the order specified.
|
The data is written in the order specified.
|
||||||
@@ -51,7 +57,7 @@ __writev (int fd, const struct iovec *vector, int count)
|
|||||||
since it's faster for small buffer sizes but can handle larger
|
since it's faster for small buffer sizes but can handle larger
|
||||||
allocations as well. */
|
allocations as well. */
|
||||||
|
|
||||||
struct scratch_buffer buf;
|
struct scratch_buffer __attribute__ ((__cleanup__ (ifree))) buf;
|
||||||
scratch_buffer_init (&buf);
|
scratch_buffer_init (&buf);
|
||||||
if (!scratch_buffer_set_array_size (&buf, 1, bytes))
|
if (!scratch_buffer_set_array_size (&buf, 1, bytes))
|
||||||
/* XXX I don't know whether it is acceptable to try writing
|
/* XXX I don't know whether it is acceptable to try writing
|
||||||
@@ -75,8 +81,6 @@ __writev (int fd, const struct iovec *vector, int count)
|
|||||||
|
|
||||||
ssize_t bytes_written = __write (fd, buffer, bytes);
|
ssize_t bytes_written = __write (fd, buffer, bytes);
|
||||||
|
|
||||||
scratch_buffer_free (&buf);
|
|
||||||
|
|
||||||
return bytes_written;
|
return bytes_written;
|
||||||
}
|
}
|
||||||
libc_hidden_def (__writev)
|
libc_hidden_def (__writev)
|
||||||
|
Reference in New Issue
Block a user