From 699663614a28ab06ed84e868b3b42ea9e8cae2a0 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Thu, 19 Apr 2007 00:15:30 +0300 Subject: [PATCH] l_pipe_read: Don't leak the old block if mem_realloc fails. --- src/scripting/lua/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/scripting/lua/core.c b/src/scripting/lua/core.c index fcd717648..bd1b8df0c 100644 --- a/src/scripting/lua/core.c +++ b/src/scripting/lua/core.c @@ -204,8 +204,10 @@ l_pipe_read(LS) size_t l = fread(buf, 1, sizeof(buf), fp); if (l > 0) { - s = mem_realloc(s, len + l); - if (!s) goto lua_error; + unsigned char *news = mem_realloc(s, len + l); + + if (!news) goto lua_error; + s = news; memcpy(s + len, buf, l); len += l;