From: Mart Lubbers Date: Thu, 25 Aug 2016 13:25:24 +0000 (+0200) Subject: fix memory bug and free the buffer when finished X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=513a91152547e9f167d3981fc5bef4f18dd04776;p=bf.git fix memory bug and free the buffer when finished --- 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;