annolinux / gnome-mplayer

Automatically exported from code.google.com/p/gnome-mplayer
0 stars 0 forks source link

found a resource leak in file support.c #206

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1. gnome-mplayer-0.9.6$ cppcheck -a -q -v -f -j3 .
2. output: [gnome-mplayer-0.9.6/src/support.c:514]: (error) Resource leak: fp

This resource leak was detected by using the static code analyis tool
cppcheck. It prints a waring about a resource leak at file
src/nautilus_property_page.c at line 514. Take a look at the code.
    fp = fopen(filename, "r");
    buffer = g_new0(gchar, 1024);

    if (fp != NULL) {
        while (!feof(fp)) {
            memset(buffer, 0, sizeof(buffer));
            buffer = fgets(buffer, 1024, fp);
            if (buffer != NULL) {
                output = g_strsplit(buffer, "\r", 0);
                ac = 0;
                while (output[ac] != NULL) {
                    g_strchomp(output[ac]);
                    g_strchug(output[ac]);
                    if (g_strncasecmp(output[ac], "rtsp://",
strlen("rtsp://")) == 0) {
                        ret = 1;
                        add_item_to_playlist(output[ac], 0);
                    } else if (g_strncasecmp(output[ac], "pnm://",
strlen("pnm://")) == 0) {
                        ret = 1;
                        add_item_to_playlist(output[ac], 0);
                    }
                    ac++;
                }
                g_strfreev(output);
            }
            if (ret != 1)
                break;
        }
    }
    g_free(buffer);
    buffer = NULL;

A possible solution might be to append  fclose(fp); at the end before the
return;

    g_free(buffer);
    buffer = NULL;
    if(fp!=NULL) fclose(fp);

    return ret;

Best regards

Ettl Martin

What version of the product are you using?
 gnome-mplayer-0.9.6

On what operating system?
Ubuntu-Linux, Jaunty 9.04, 32-Bit

Original issue reported on code.google.com by ettl.mar...@gmail.com on 16 Jun 2009 at 8:30

GoogleCodeExporter commented 9 years ago
Bug was in support.c and I fixed it in the if statement.

Original comment by kdeko...@gmail.com on 16 Jun 2009 at 9:47