Fixed memory leak in input.c, resize buf BEFORE adding to it