From 8194c7d6c5489563cc1e73f4362864e434f85e2a Mon Sep 17 00:00:00 2001 From: Casper Date: Sat, 1 Oct 2022 19:01:31 +0200 Subject: Make buffer and size static to avoid memory leak getline() allocates/reallocates memory dynamically. When center() is called repeatedly it would leak memory. Make them static so the same memory is reallocated all the time, and none is lost. No need to free manually, let the OS take care of that. --- center.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/center.c b/center.c index 10e8130..d4d724e 100644 --- a/center.c +++ b/center.c @@ -101,8 +101,8 @@ main(int argc, char **argv) void center(FILE *fp) { - char *line = NULL; - size_t bs = 0; + static char *line = NULL; + static size_t bs = 0; while (getline(&line, &bs, fp) != -1) { int len, tabs = 0; -- cgit v1.2.3