commit:     ff39a244215a4ee206bff0a78deb702d9c9702dc
Author:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Sat Mar  8 19:22:18 2025 +0000
Commit:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Sat Mar  8 19:36:04 2025 +0000
URL:        https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=ff39a244

libsbutil: sb_write_fd: use a small buffer on the stack

Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>

 libsbutil/sb_write_fd.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libsbutil/sb_write_fd.c b/libsbutil/sb_write_fd.c
index f19d7de..fdcd34e 100644
--- a/libsbutil/sb_write_fd.c
+++ b/libsbutil/sb_write_fd.c
@@ -12,16 +12,15 @@
 
 int sb_copy_file_to_fd(const char *file, int ofd)
 {
+       char buf[128];
        int ret = -1;
 
        int ifd = sb_open(file, O_RDONLY|O_CLOEXEC, 0);
        if (ifd == -1)
                return ret;
 
-       size_t pagesz = getpagesize();
-       char *buf = xmalloc(pagesz);
        while (1) {
-               size_t len = sb_read(ifd, buf, pagesz);
+               size_t len = sb_read(ifd, buf, sizeof(buf));
                if (len == -1)
                        goto error;
                else if (!len)
@@ -37,6 +36,5 @@ int sb_copy_file_to_fd(const char *file, int ofd)
        ret = 0;
  error:
        sb_close(ifd);
-       free(buf);
        return ret;
 }

Reply via email to