fix memory bug and free the buffer when finished
authorMart Lubbers <mart@martlubbers.net>
Thu, 25 Aug 2016 13:25:24 +0000 (15:25 +0200)
committerMart Lubbers <mart@martlubbers.net>
Thu, 25 Aug 2016 13:25:24 +0000 (15:25 +0200)
bf.c

diff --git a/bf.c b/bf.c
index c095176..ef5dd39 100644 (file)
--- 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;