From fc815b12c12096b55518a15e036204dd62672e4c Mon Sep 17 00:00:00 2001 From: Mukund Sivaraman Date: Sun, 24 Aug 2008 12:07:24 +0530 Subject: [PATCH] Move buffer to the heap due to its size --- src/buffer.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index 1d48e0c..07a2e7b 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -212,7 +212,7 @@ ssize_t read_buffer(int fd, struct buffer_s * buffptr) { ssize_t bytesin; - unsigned char buffer[READ_BUFFER_SIZE]; + unsigned char *buffer; assert(fd >= 0); assert(buffptr != NULL); @@ -223,20 +223,23 @@ read_buffer(int fd, struct buffer_s * buffptr) if (buffptr->size >= MAXBUFFSIZE) return 0; + buffer = safemalloc(READ_BUFFER_SIZE); + if (!buffer) { + return -ENOMEM; + } + bytesin = read(fd, buffer, READ_BUFFER_SIZE); if (bytesin > 0) { if (add_to_buffer(buffptr, buffer, bytesin) < 0) { log_message(LOG_ERR, "readbuff: add_to_buffer() error."); - return -1; + bytesin = -1; } - - return bytesin; } else { if (bytesin == 0) { /* connection was closed by client */ - return -1; + bytesin = -1; } else { switch (errno) { #ifdef EWOULDBLOCK @@ -247,15 +250,20 @@ read_buffer(int fd, struct buffer_s * buffptr) # endif #endif case EINTR: - return 0; + bytesin = 0; + break; default: log_message(LOG_ERR, "readbuff: recv() error \"%s\" on file descriptor %d", strerror(errno), fd); - return -1; + bytesin = -1; + break; } } } + + safefree(buffer); + return bytesin; } /*