diff options
author | Casper Andersson <casper.casan@gmail.com> | 2022-10-01 19:01:31 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2022-10-01 20:09:57 +0200 |
commit | 8194c7d6c5489563cc1e73f4362864e434f85e2a (patch) | |
tree | f8fcd020eb2f706cda9e7ae064b3d7f3becde78f /center.c | |
parent | 4f4d8f03a9488e482ca59e8985c4a5d60ed82af3 (diff) |
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.
Diffstat (limited to 'center.c')
-rw-r--r-- | center.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -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; |