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 755632 - Memory leak in handle_setup_request
Memory leak in handle_setup_request
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-rtsp-server
1.4.5
Other Windows
: Normal normal
: 1.8.4
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2015-09-25 15:04 UTC by Nikita Bobkov
Modified: 2016-10-25 13:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Possible fix of GstRTSPMedia leak (772 bytes, patch)
2015-09-25 15:04 UTC, Nikita Bobkov
needs-work Details | Review
test-readme.c with leak (2.32 KB, text/plain)
2015-09-28 15:20 UTC, Nikita Bobkov
  Details
Possible fix leak (1.62 KB, patch)
2016-08-01 15:29 UTC, Kseniya Vasilchuk
rejected Details | Review
rtsp-client: Fix leaking of media in error cases (1017 bytes, patch)
2016-08-02 12:17 UTC, Sebastian Dröge (slomo)
none Details | Review
rtsp-client: Fix leaking of session in error cases (2.02 KB, patch)
2016-08-02 12:17 UTC, Sebastian Dröge (slomo)
committed Details | Review
rtsp-client: Fix leaking of media in error cases (2.27 KB, patch)
2016-08-02 14:46 UTC, Sebastian Dröge (slomo)
committed Details | Review

Description Nikita Bobkov 2015-09-25 15:04:55 UTC
Created attachment 312154 [details] [review]
Possible fix of GstRTSPMedia leak

In cases of some errors object of type GstRTSPMedia can leak. A pipeline of media leaks as well.
Comment 1 Tim-Philipp Müller 2015-09-26 10:13:17 UTC
Thanks for the patch. How did you find/trigger this leak? It might be good to add a unit test for that.

The unref in cleanup_transport causes assertion failures in our unit test suite, so something's not quite right with that or with the existing code. The other one isn't in a code path that's covered by the unit test, but it would be good to understand the critical from the last one first anyway.

Please also attach a patch in 'git format-patch' format if possible at all.
Comment 2 Tim-Philipp Müller 2015-09-26 10:14:15 UTC
Also, could you re-check if the leak still happens with the just-released 1.6.0? (windows binaries will be available shortly)
Comment 3 Nikita Bobkov 2015-09-28 13:51:59 UTC
I have restricted the list of supported transports of RTSP media factory to TCP only so RTSP client tries UDP first, gets an error and then retries TCP. I found that find_media refs media object each time it is called but it is not always unrefed later on. GST_TRACE=mem-live highlights the leak.

Which test fails? tests\check\gst\client.c passes. At least in 1.4.5 with my patch. And after I bound socket (g_socket_bind) before passing it to gst_rtsp_connection_create_from_socket... Have I just found another bug?

I have to work with code commited to our SVN server so using Git just to create a single patch doesn't seem very convenient for me. Is it alright if I'll continue using svn diff for patches? If Git complains GNU patch should probably accept them without problems.

I tried 1.6.0 windows binaries but my application failed to run at all. It complains about appsrc element being missing. gst-inspect-1.0 doesn't see it either. libgstapp.dll is also not present in lib\gstreamer-1.0. Is it supposed to be like this?
Comment 4 Tim-Philipp Müller 2015-09-28 14:05:16 UTC
Yes, we can make simple diff patches work, that's not a problem.

I don't know about those problems, perhaps you're missing some plugin modules like gst-plugins-base?

If you have a simple test program that reproduces the leak, that would also be helpful.
Comment 5 Nikita Bobkov 2015-09-28 15:20:03 UTC
Created attachment 312312 [details]
test-readme.c with leak

Reinstalled everything and now it finds all elements. However the leak still seems to be there.

I took test-readme.c and added the line:
gst_util_set_object_arg(G_OBJECT(factory), "protocols", "tcp");
Then I ran it with GST_TRACE=mem-live, connected 5 times with VLC and terminated it. In the output I see 5 lines like this:

GstPipeline          : (1) 0000000004522A80
Comment 6 Kseniya Vasilchuk 2016-08-01 15:29:57 UTC
Created attachment 332481 [details] [review]
Possible fix leak
Comment 7 Kseniya Vasilchuk 2016-08-01 15:33:37 UTC
As well as reporter, I found the leak with GstRTSPMedia objects.
I also found that some objects don't have unref after reffering in find_media function, so I've just added it in patch above.

Used 1.8.2 version on Linux.
Comment 8 Sebastian Dröge (slomo) 2016-08-02 12:00:26 UTC
Comment on attachment 332481 [details] [review]
Possible fix leak

This is also all covered by the initial patch: cleanup_transport unrefs the media there.
Comment 9 Sebastian Dröge (slomo) 2016-08-02 12:17:34 UTC
Created attachment 332545 [details] [review]
rtsp-client: Fix leaking of media in error cases
Comment 10 Sebastian Dröge (slomo) 2016-08-02 12:17:39 UTC
Created attachment 332546 [details] [review]
rtsp-client: Fix leaking of session in error cases
Comment 11 Sebastian Dröge (slomo) 2016-08-02 12:18:18 UTC
(In reply to Sebastian Dröge (slomo) from comment #9)
> Created attachment 332545 [details] [review] [review]
> rtsp-client: Fix leaking of media in error cases

This breaks the gst/client unit test
Comment 12 Sebastian Dröge (slomo) 2016-08-02 12:19:10 UTC
Comment on attachment 332546 [details] [review]
rtsp-client: Fix leaking of session in error cases

Attachment 332546 [details] pushed as 687301a - rtsp-client: Fix leaking of session in error cases
Comment 13 Kseniya Vasilchuk 2016-08-02 14:19:12 UTC
(In reply to Sebastian Dröge (slomo) from comment #12)
> Comment on attachment 332546 [details] [review] [review]
> rtsp-client: Fix leaking of session in error cases
> 
> Attachment 332546 [details] pushed as 687301a - rtsp-client: Fix leaking of
> session in error cases

I'm sure your commit is useful but the initial report was about GstRTSPMedia objects memory leak... and it still here. You can check it like suggested in Nikita's comment #5.

My patch resolved the problem at least for me.

What about Nikita Bobkov patch I think it is OK too, but for 1.4.5 version. The reason why it failed in new version test suits is that it causes one more unref than needed in the case of 'unsupported_client_transport'. At 1.4.5 version 'unsupported_client_transport' label with 'cleanup_transport' label inside it was before last media object unref.
Comment 14 Sebastian Dröge (slomo) 2016-08-02 14:46:24 UTC
Created attachment 332564 [details] [review]
rtsp-client: Fix leaking of media in error cases

With additional fixes by Kseniya Vasilchuk <vailchukkseniia@gmail.com>
and myself to make the media refcounting a bit easier to follow.
Comment 15 Sebastian Dröge (slomo) 2016-08-02 14:47:29 UTC
This one fixes that, and also a few other refcounting issues there.
Comment 16 Sebastian Dröge (slomo) 2016-08-02 14:47:47 UTC
commit de3d0c4522fb4b29887f43c2f274c27b1d0d2209
Author: Nikita Bobkov <NikitaDBobkov@gmail.com>
Date:   Fri Sep 25 15:04:00 2015 +0000

    rtsp-client: Fix leaking of media in error cases
    
    With additional fixes by Kseniya Vasilchuk <vasilchukkseniia@gmail.com>
    and myself to make the media refcounting a bit easier to follow.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=755632