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 687471 - rtsp: fix memory leaks under error conditions
rtsp: fix memory leaks under error conditions
Status: RESOLVED WONTFIX
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
git master
Other Linux
: Normal normal
: NONE
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2012-11-02 19:05 UTC by Miguel Angel Cabrera Moya
Modified: 2012-11-06 19:01 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
proposed fix (1.89 KB, patch)
2012-11-02 19:06 UTC, Miguel Angel Cabrera Moya
rejected Details | Review

Description Miguel Angel Cabrera Moya 2012-11-02 19:05:26 UTC
When there are errors in calling some functions there are memory leaks
Comment 1 Miguel Angel Cabrera Moya 2012-11-02 19:06:19 UTC
Created attachment 227918 [details] [review]
proposed fix
Comment 2 Tim-Philipp Müller 2012-11-02 19:43:01 UTC
I don't know about these. I'm tempted to WONTFIX these.

We never care about memory leaks as a result of g_return_*() - those are just sanity checks to help spot programming bugs during development, rather than crashing right away.

But even if not, functions that take ownership of arguments should do so at *all* times, whether they then return an error or not, so it should never be the caller freeing stuff after giving away ownership, that's just wrong calling conventions IMHO.

However, I see that this is handled like this elsewhere in the code.. (e.g. gst_rtsp_message_add_header).

So in a way my objection to this patch is that it perpetuates this madness even more ;)

Setting to NEEDINFO, to see what other developers (and the reporter) think.
Comment 3 Miguel Angel Cabrera Moya 2012-11-04 12:01:53 UTC
I agree with Tim if a function says it takes ownership of a value should do so always.

Thinking about this corner case it can be fixed this way. It's a bit ugly but it works. If you agree I can make a patch with this fix.

#include <glib.h>

void
main()
{
  gchar *x = g_strdup ("eserse");
  g_return_if_fail (NULL != NULL || (
          {
            g_free (x);
            FALSE;
          }
      ));
}
Comment 4 Tim-Philipp Müller 2012-11-06 19:00:40 UTC
> Thinking about this corner case it can be fixed this way. It's a bit ugly but
> it works. If you agree I can make a patch with this fix.
> 
> #include <glib.h>
> 
> void
> main()
> {
>   gchar *x = g_strdup ("eserse");
>   g_return_if_fail (NULL != NULL || (
>           {
>             g_free (x);
>             FALSE;
>           }
>       ));
> }


Yeah, let's not do that. I think this is using a gcc and/or c99 extension anyway, but it could probably be done differently as well; but still, let's not.

I would suggest you either teach coverity or whatever tool you're using about g_return_*(), or make it process things with -DG_DISABLE_ASSERTS (or whatever the right define is).