[git commit] xmalloc_[open_]read[_close]: do not ignore xrealloc return value

Denys Vlasenko vda.linux at googlemail.com
Fri May 15 21:23:23 UTC 2009


commit: http://git.busybox.net/busybox/commit/?id=071ede1e5de784820f39c2546000c08d74b12f6d
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master


Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 include/libbb.h |    6 ++++++
 libbb/read.c    |    4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/libbb.h b/include/libbb.h
index 128aa92..bae7efb 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -965,6 +965,12 @@ enum {
 	/* How long the longest ESC sequence we know? */
 	KEYCODE_BUFFER_SIZE = 4
 };
+/* Note: fd may be in blocking or non-blocking mode, both make sense.
+ * For one, less uses non-blocking mode.
+ * Only the first read syscall inside read_key may block indefinitely
+ * (unless fd is in non-blocking mode),
+ * subsequent reads will time out after a few milliseconds.
+ */
 int read_key(int fd, smalluint *nbuffered, char *buffer) FAST_FUNC;
 
 
diff --git a/libbb/read.c b/libbb/read.c
index a0c0cc6..b58982b 100644
--- a/libbb/read.c
+++ b/libbb/read.c
@@ -229,7 +229,7 @@ void* FAST_FUNC xmalloc_read(int fd, size_t *maxsz_p)
 		if (size > 64*1024)
 			size = 64*1024;
 	}
-	xrealloc(buf, total + 1);
+	buf = xrealloc(buf, total + 1);
 	buf[total] = '\0';
 
 	if (maxsz_p)
@@ -273,7 +273,7 @@ void* FAST_FUNC xmalloc_open_read_close(const char *filename, size_t *maxsz_p)
 		free(buf);
 		return NULL;
 	}
-	xrealloc(buf, size + 1);
+	buf = xrealloc(buf, size + 1);
 	buf[size] = '\0';
 
 	if (maxsz_p)
-- 
1.6.0.6


More information about the busybox-cvs mailing list