GNOME Bugzilla – Bug 664133
[0.11] adapter: automatically unmap on clearing
Last modified: 2012-01-14 19:53:44 UTC
adapter: automatically unmap on clearing Posted here for comments, as it's not such a great solution, more like the least worst.
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.
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.
Another possibly way to fix this issue: https://bugzilla.gnome.org/show_bug.cgi?id=665003
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