From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1792) id DB50A3858D35; Tue, 20 Jun 2023 16:37:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB50A3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1687279047; bh=RT1ngg5ApXHO9YUj+YHMohs6OMraQnsGkyOuUCB/2rA=; h=From:To:Subject:Date:From; b=eG/cDtgyvHe4D1VvB4kuwoeN2kJEIgDjvmPzxK1sWoaRCqJ2jRoo1e76m9Nbf1M+v 4MHbBz8n6J0Z0qP4J0MhgQU7x+AhB72nLNu6MYt71EDAJVGeRSs6QGB78wa0WlrNPv hbCHEQuN54ZVTI414csfRoomQEvHRQwFuw9bU7Vo= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Samuel Thibault To: glibc-cvs@sourceware.org Subject: [glibc] hurd: writev: Add back cleanup handler X-Act-Checkin: glibc X-Git-Author: Joe Simmons-Talbott X-Git-Refname: refs/heads/master X-Git-Oldrev: 4290aed05135ae4c0272006442d147f2155e70d7 X-Git-Newrev: c6957bddb939a1a602824b9fa731fc45fb4a6d8c Message-Id: <20230620163727.DB50A3858D35@sourceware.org> Date: Tue, 20 Jun 2023 16:37:27 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c6957bddb939a1a602824b9fa731fc45fb4a6d8c commit c6957bddb939a1a602824b9fa731fc45fb4a6d8c Author: Joe Simmons-Talbott Date: Mon Jun 19 10:38:42 2023 -0400 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 cf30aa43a5917f441c9438aaee201c53c8e1d76b. Checked on i686-gnu and x86_64-linux-gnu. Message-Id: <20230619143842.2901522-1-josimmon@redhat.com> Diff: --- sysdeps/posix/writev.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sysdeps/posix/writev.c b/sysdeps/posix/writev.c index d4c3cf6f03..0c86e7ea5e 100644 --- a/sysdeps/posix/writev.c +++ b/sysdeps/posix/writev.c @@ -26,6 +26,12 @@ #include +static void +ifree (struct scratch_buffer *sbuf) +{ + scratch_buffer_free (sbuf); +} + /* Write data pointed by the buffers described by VECTOR, which is a vector of COUNT 'struct iovec's, to file descriptor FD. 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 allocations as well. */ - struct scratch_buffer buf; + struct scratch_buffer __attribute__ ((__cleanup__ (ifree))) buf; scratch_buffer_init (&buf); if (!scratch_buffer_set_array_size (&buf, 1, bytes)) /* 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); - scratch_buffer_free (&buf); - return bytes_written; } libc_hidden_def (__writev)