annolinux / gnome-mplayer

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

found a possible memory leak in file support.c at line 1282 #210

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
1. cppcheck -q -a -v -f -j2 gnome-mplayer-0.9.6/
2. [gnome-mplayer-0.9.6/src/support.c:1282]: (error) Memory leak: ret

The static code analysis tool complained about line 1282.
Take a loop at line 1282:
.....
    if (error != NULL) {
        printf("Error when running: %s\n", error->message);
        g_error_free(error);
        error = NULL;
        if (out != NULL)
            g_free(out);
        if (err != NULL)
1282         g_free(err);
        return NULL;
    }
.....

The function returns without freeing the memory of variable ret.

A possible way to avoid this memory leak is:

    if (error != NULL) {
        printf("Error when running: %s\n", error->message);
        g_error_free(error);
        error = NULL;
        if (out != NULL)
            g_free(out);
        if (err != NULL)
1282         g_free(err);
        if(ret !=NULL)
             g_free(ret);
        return NULL;
    }

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

On what operating system?
Ubuntu Linux(Jaunty,32-Bit,g++-4.3.2)

Best regards

Ettl Martin

Original issue reported on code.google.com by ettl.mar...@gmail.com on 20 Jun 2009 at 11:28

GoogleCodeExporter commented 8 years ago
Code analysis appears to be wrong in this case, as ret is not initialized until 
after
this code.

Original comment by kdeko...@gmail.com on 21 Jun 2009 at 2:55

GoogleCodeExporter commented 8 years ago
Sorry, but you are maybe wrong.
Take a look at line 1216:

    if (device_name(uri)) {
        name = g_strdup(uri);
        if (ret == NULL)
1216         ret = (MetaData *) g_new0(MetaData, 1);

This is before 1282 and ret is initialized.

Cheers

Martin

Original comment by ettl.mar...@gmail.com on 21 Jun 2009 at 11:19

GoogleCodeExporter commented 8 years ago
Ok, I went ahead an patched it as I confirmed what you found.

Original comment by kdeko...@gmail.com on 21 Jun 2009 at 12:48