After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 756864 - stats: memory leak when fgets() fails
stats: memory leak when fgets() fails
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Linux
: Normal normal
: 1.7.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2015-10-20 12:50 UTC by Luis de Bethencourt
Modified: 2015-10-21 10:22 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
proposed patch (741 bytes, patch)
2015-10-20 12:50 UTC, Luis de Bethencourt
committed Details | Review

Description Luis de Bethencourt 2015-10-20 12:50:07 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.
Comment 1 Luis de Bethencourt 2015-10-20 12:52:50 UTC
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).
Comment 2 Luis de Bethencourt 2015-10-21 10:21:12 UTC
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
Comment 3 Luis de Bethencourt 2015-10-21 10:22:40 UTC
Review of attachment 313743 [details] [review]:

merged