aboutsummaryrefslogtreecommitdiff
path: root/center.c
diff options
context:
space:
mode:
authorCasper Andersson <casper.casan@gmail.com> 2022-10-01 19:01:31 +0200
committerThomas Voss <mail@thomasvoss.com> 2022-10-01 20:09:57 +0200
commit8194c7d6c5489563cc1e73f4362864e434f85e2a (patch)
treef8fcd020eb2f706cda9e7ae064b3d7f3becde78f /center.c
parent4f4d8f03a9488e482ca59e8985c4a5d60ed82af3 (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.c4
1 files 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;