aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-26 10:53:55 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-26 10:53:55 -0200
commit89f98c099576591f8f65b9526d0f24de6dec95e8 (patch)
tree153ee308d5f8240e1299802dedb5a9c93c35b6a7
parentb892f0a8774f573d7ec9b02617428871b8d3a2b3 (diff)
downloadlua-89f98c099576591f8f65b9526d0f24de6dec95e8.tar.gz
lua-89f98c099576591f8f65b9526d0f24de6dec95e8.tar.bz2
lua-89f98c099576591f8f65b9526d0f24de6dec95e8.zip
in function `read_file', realloc() doesn't free the buffer if it can't
allocate new memory
-rw-r--r--bugs6
-rw-r--r--liolib.c9
2 files changed, 12 insertions, 3 deletions
diff --git a/bugs b/bugs
index 7c970c14..92c172ed 100644
--- a/bugs
+++ b/bugs
@@ -229,3 +229,9 @@ Wed Sep 27 13:39:45 EST 2000
229>> (e.g. «a = {print'foo'}») 229>> (e.g. «a = {print'foo'}»)
230(by Edgar Toernig; since 4.0b, deriving from previous bug) 230(by Edgar Toernig; since 4.0b, deriving from previous bug)
231 231
232** liolib.c
233Thu Oct 26 10:50:46 EDT 2000
234>> in function `read_file', realloc() doesn't free the buffer if it can't
235>> allocate new memory
236(by Mauro Vezzosi; since 4.0b)
237
diff --git a/liolib.c b/liolib.c
index b1fddebe..d71965a6 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 1.87 2000/10/20 16:39:03 roberto Exp roberto $ 2** $Id: liolib.c,v 1.88 2000/10/26 12:47:05 roberto Exp roberto $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -345,9 +345,12 @@ static void read_file (lua_State *L, FILE *f) {
345 size_t size = BUFSIZ; 345 size_t size = BUFSIZ;
346 char *buffer = NULL; 346 char *buffer = NULL;
347 for (;;) { 347 for (;;) {
348 buffer = (char *)realloc(buffer, size); 348 char *newbuffer = (char *)realloc(buffer, size);
349 if (buffer == NULL) 349 if (newbuffer == NULL) {
350 free(buffer);
350 lua_error(L, "not enough memory to read a file"); 351 lua_error(L, "not enough memory to read a file");
352 }
353 buffer = newbuffer;
351 len += fread(buffer+len, sizeof(char), size-len, f); 354 len += fread(buffer+len, sizeof(char), size-len, f);
352 if (len < size) break; /* did not read all it could */ 355 if (len < size) break; /* did not read all it could */
353 size *= 2; 356 size *= 2;