gstmodule: _remap: fix memory leak
The memory in info is a pointer to GstMemory, it is unmapped with gst_buffer_unmap() or gst_memory_unmap()
An extra copy of GstMemory in not needed in this case, because it is always present until the call of _unmap()
The extra copy cause memory leak in some cenarios with python plugins.
This piece of code can be used to check the memory leak on master branch, to run this:
mkdir python
cd python
python map_bug.py
map_bug.py
'''
GST_PLUGIN_PATH=.. GST_DEBUG=python:4 gst-launch-1.0 videotestsrc ! map_bug ! videorate ! fakevideosink
'''
import gi
gi.require_version('GstBase', '1.0')
from gi.repository import Gst, GObject, GstBase
Gst.init(None)
#
# Simple MapBug element created entirely in python
#
class MapBug(GstBase.BaseTransform):
__gstmetadata__ = ('MapBug Python','Transform', \
'Simple identity element written in python', 'Marianna S. Buschle')
__gsttemplates__ = (Gst.PadTemplate.new("src",
Gst.PadDirection.SRC,
Gst.PadPresence.ALWAYS,
Gst.Caps.new_any()),
Gst.PadTemplate.new("sink",
Gst.PadDirection.SINK,
Gst.PadPresence.ALWAYS,
Gst.Caps.new_any()))
def __init__(self):
'''
https://www.kernel.org/doc/Documentation/filesystems/proc.txt
'''
self.labels = ('size:', ' resident:', ' shared:', ' trs:', ' lrs:', ' drs:', ' dt:')
def do_transform_ip(self, buffer):
info = buffer.map(Gst.MapFlags.READ | Gst.MapFlags.WRITE)
buffer.unmap(info)
self.process_memory_status()
return Gst.FlowReturn.OK
def process_memory_status(self):
with open('/proc/self/statm') as f:
statm = list(f.read().split())
info = "".join(i + j for i, j in zip(self.labels, statm))
Gst.info(info)
GObject.type_register(MapBug)
__gstelementfactory__ = ("map_bug", Gst.Rank.NONE, MapBug)
Edited by Jose Quaresma