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 664133 - [0.11] adapter: automatically unmap on clearing
[0.11] adapter: automatically unmap on clearing
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
unspecified
Other All
: Normal normal
: 0.11.x
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2011-11-15 17:47 UTC by Vincent Penquerc'h
Modified: 2012-01-14 19:53 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
adapter: automatically unmap on clearing (1.43 KB, patch)
2011-11-15 17:47 UTC, Vincent Penquerc'h
committed Details | Review

Description Vincent Penquerc'h 2011-11-15 17:47:23 UTC
adapter: automatically unmap on clearing

Posted here for comments, as it's not such a great solution,
more like the least worst.
Comment 1 Vincent Penquerc'h 2011-11-15 17:47:25 UTC
Created attachment 201468 [details] [review]
adapter: automatically unmap on clearing

When _clear gets called between _map and _unmap, buffers
will be unreffed. If the adapter was mapped, memory leaks
may occur.
While calling _clear between _map and _unmap does not seem
like such a great idea, this is possible in the audio
encoder base class, as _clear may be called in _finish_frame.
Since the audio encoder relies on flushing to keep track of
timestamps, delaying flushing till after handle_frame seems
dangerous.
So, we unmap on clear, as the next unmap will do nothing.
This makes _clear safe to call between _map and _unmap,
while avoiding leaking the mapped buffer.
Comment 2 Mark Nauwelaerts 2012-01-05 12:25:08 UTC
This seems not only a problem with gst_adapter_clear.  The audiocodec classes will routinely call gst_adapter_flush in _finish_frame which may lead to dropping the leading adapter buffer which could have been mapped.  That one will not be around later on to unmap and will lead to _unmap on the wrong buffer at adapter_unmap time.
Comment 3 Vincent Penquerc'h 2012-01-06 11:45:21 UTC
Another possibly way to fix this issue:
https://bugzilla.gnome.org/show_bug.cgi?id=665003
Comment 4 Mark Nauwelaerts 2012-01-14 19:53:23 UTC
IMO, adapter should handle these cases (the audiocodec class indicating a definite need for this).  Having adapter _unmap and clean up when needed has similar/exact semantics and dangers for "user-side" as in 0.10 (regarding a _peek data pointer versus _flush etc).

Following commits should fix this then:

commit 12757e604a894533b8fcd80a128eee528a613851
Author: Vincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Date:   Tue Nov 15 17:42:56 2011 +0000

    adapter: automatically unmap on clearing
    
    When _clear gets called between _map and _unmap, buffers
    will be unreffed. If the adapter was mapped, memory leaks
    may occur.
    While calling _clear between _map and _unmap does not seem
    like such a great idea, this is possible in the audio
    encoder base class, as _clear may be called in _finish_frame.
    Since the audio encoder relies on flushing to keep track of
    timestamps, delaying flushing till after handle_frame seems
    dangerous.
    So, we unmap on clear, as the next unmap will do nothing.
    This makes _clear safe to call between _map and _unmap,
    while avoiding leaking the mapped buffer.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=664133

commit ea2f87d34e72a268d5607661ebc80703b2fc8d50
Author: Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Date:   Wed Jan 11 10:59:53 2012 +0100

    adapter: ensure automagic _unmap in some more cases