annolinux / gnome-mplayer

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

found a missmatch in allocation and deallocation #207

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. cppcheck -q -a -v -j2 -f gnome-mplayer-0.9.6/
2. [gnome-mplayer-0.9.6/src/support.c:1573]: (error) Mismatching allocation
and deallocation: local_uri

A missmatch in allocation and deallocation happens when when memory is
allocated using new and deallocation with free() for example. Here the
memory is allocated with the function strdup(), at line 1553. strdup
returns memory that has to be deallocated with free(), not with g_free(),
as done at line 1574!

A possible way out is:

gboolean add_item_to_playlist(const gchar * uri, gint playlist)
{
....
        if (g_str_has_prefix(uri, "http://")) {
            unescaped = switch_protocol(uri, "mmshttp");
            free(local_uri);
            local_uri = g_strdup(unescaped);
            g_free(unescaped);
        }
....
}

Reference:
http://www.opengroup.org/onlinepubs/009695399/functions/strdup.html
http://library.gnome.org/devel/glib/unstable/glib-Memory-Allocation.html

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

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

Best regards

Ettl Martin.

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

GoogleCodeExporter commented 8 years ago
In 0.9.6 local_uri was allocated with strdup. I had already fixed the g_free, 
but now
I changed the strdup to g_strdup.

I don't think this is really that much of an issue since the g_ wrappers just 
call
the base function anyway.

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