[PATCH v2 1/2] copyfd: reinstate proper guard around munmap()

Johannes Schindelin johannes.schindelin at gmx.de
Fri Jul 14 20:25:55 UTC 2017


In 4c1392296 (Introduce FEATURE_COPYBUF_KB, 2007-12-02), a feature was
introduced where a large stack was allocated via mmap(), and
consequently released via munmap(). Since this is overkill for small
stacks, the mmap()/munmap() code was guarded inside an #if
CONFIG_FEATURE_COPYBUF_KB > 4 ... #endif guard.

In pure Win32 API, there is no support to abuse mmap() to allocate a
stack that way, therefore the code is simply disabled in busybox-w32.

But 8d75d794e (libbb: use sendfile() to copy data between file
descriptors, 2014-11-27) removed that guard around the munmap() call.
That was most likely a mistake, as the corresponding mmap() call is
*still* inside an equivalent #if ... #endif guard.

Let's revert the mistaken change.

Signed-off-by: Johannes Schindelin <johannes.schindelin at gmx.de>
---
 libbb/copyfd.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libbb/copyfd.c b/libbb/copyfd.c
index 7e3531903..eedf03790 100644
--- a/libbb/copyfd.c
+++ b/libbb/copyfd.c
@@ -119,8 +119,10 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
 	}
  out:
 
+#if CONFIG_FEATURE_COPYBUF_KB > 4
 	if (buffer_size > 4 * 1024)
 		munmap(buffer, buffer_size);
+#endif
 	return status ? -1 : total;
 }
 
-- 
2.13.3.windows.1.13.gaf0c2223da0




More information about the busybox mailing list