Quantcast

from: getline(3) can fail

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

from: getline(3) can fail

Scott Cheloha
Check whether or not getline(3) failed before exiting.

It also couldn't hurt to close fp... especially given that we're
freeing line, too, right before exit.

Thoughts?

--
Scott Cheloha

Index: from.c
===================================================================
RCS file: /cvs/src/usr.bin/from/from.c,v
retrieving revision 1.24
diff -u -p -r1.24 from.c
--- from.c      5 Nov 2015 18:42:41 -0000       1.24
+++ from.c      21 Apr 2017 01:56:48 -0000
@@ -98,6 +98,9 @@ main(int argc, char *argv[])
                newline = 0;
        }
        free(line);
+       if (ferror(fp))
+               err(1, "getline");
+       fclose(fp);
        exit(EXIT_SUCCESS);
 }
 

Loading...