GNOME Bugzilla – Bug 756864
stats: memory leak when fgets() fails
Last modified: 2015-10-21 10:22:40 UTC
Created attachment 313743 [details] [review] proposed patch There are multiple reasons why fgets() could fail, but in all of them we still want to free the open file log.
For easy reviewing, this is the beginning of the function collect_stats(). static void collect_stats (const gchar * filename) { FILE *log; if ((log = fopen (filename, "rt"))) { gchar line[5001]; /* probe format */ if (fgets (line, 5000, log)) { [...] The patch moves fclose(log) to be at the end of the true branch of if (fopen), instead of the true branch of (fgets).
commit 587b95a8574eea0c0e0e93c1bf2d1c6c9d741ec4 Author: Luis de Bethencourt <luisbg@osg.samsung.com> Date: Tue Oct 20 13:46:24 2015 +0100 stats: always free log We always want to free the open file log if fopen() succeeded. Independently of if fgets() succeeds or fails. CID 1326055 https://bugzilla.gnome.org/show_bug.cgi?id=756864
Review of attachment 313743 [details] [review]: merged