Skip to content

pyg_boxed_new cause a memory leak if it copy and free the boxed pointer

Jose Quaresma requested to merge quaresma.jose/gst-python:memory-leak into master

This MR fix issues #35 (closed) memory leak on _remap function in gstmodule. It can replace the MR !34 (merged) that try to fix the same issue with PyObject refactoring.

The two MR fixes the problem for me, this one don't touch the PyObject code. I think this is more clean and a better approach. The MR !34 (merged) can by applied latter on top of this one.

It can be checked with the this case: (The MR !34 (merged) don't fix this test case)

#!/usr/bin/env python3

import os

os.environ['GST_DEBUG'] = 'GST_TRACER:7,GST_BUFFER*:7,GST_MEMORY*:7'
os.environ['GST_TRACERS'] = 'leaks(stack-traces-flags=full,check-refs=true,filters="GstBuffer,GstMemory")'

import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst

Gst.init(None)

def map(b, p, j):
    mapinfo = b.map(Gst.MapFlags.READ | Gst.MapFlags.WRITE)
    mapinfo.data[p] += 1
    assert(mapinfo.data[p] == j + 1)
    b.unmap(mapinfo)

data = [0]*10
buffer = Gst.Buffer.new_wrapped (data)
for j in range(0, len(data)):
    map(buffer, 0, j)
    
    mapinfo = buffer.map(Gst.MapFlags.READ | Gst.MapFlags.WRITE)
    map(mapinfo.memory, 1, j)
    buffer.unmap(mapinfo)

del buffer

Gst.deinit()

Merge request reports