[hackers] [sbase] No need to free the buffer for every call to getline() || sin

From: <git_AT_suckless.org>
Date: Tue, 24 Mar 2015 23:53:38 +0100 (CET)

commit 080a1ee8333718a0b09cfbb8de12c34dfe4b4363
Author: sin <sin_AT_2f30.org>
Date: Mon Feb 9 14:10:24 2015 +0000

    No need to free the buffer for every call to getline()
    
    It will realloc as necessary if the new line size exceeds the
    capacity of the allocated buffer.

diff --git a/tail.c b/tail.c
index 3ea4739..b97ed5c 100644
--- a/tail.c
+++ b/tail.c
_AT_@ -101,13 +101,12 @@ main(int argc, char *argv[])
                         tail(fp, argv[0], n);
 
                         if (fflag && argc == 1) {
- for(;; tmp = NULL, tmpsize = 0) {
+ tmp = NULL;
+ tmpsize = 0;
+ for(;;) {
                                         while (getline(&tmp, &tmpsize, fp) != -1) {
                                                 fputs(tmp, stdout);
                                                 fflush(stdout);
- free(tmp);
- tmp = NULL;
- tmpsize = 0;
                                         }
                                         if (ferror(fp))
                                                 eprintf("readline '%s':", argv[0]);
Received on Tue Mar 24 2015 - 23:53:38 CET

This archive was generated by hypermail 2.3.0 : Wed Mar 25 2015 - 00:08:32 CET