From 513a91152547e9f167d3981fc5bef4f18dd04776 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Thu, 25 Aug 2016 15:25:24 +0200 Subject: [PATCH] fix memory bug and free the buffer when finished --- bf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bf.c b/bf.c index c095176..ef5dd39 100644 --- a/bf.c +++ b/bf.c @@ -29,10 +29,11 @@ int main(int argc, char *argv[]) while(1){ switch(fgetc(in)){ case EOF: + free(b); return EXIT_SUCCESS; case '>': ++ptr; - if(ptr > b+stacksize){ + if(ptr >= b+stacksize){ offset = ptr-b; b = realloc(b, stacksize *= 2); ptr = b+offset; -- 2.20.1