Commit 54da7712 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Merge branch 'frame-free-fix' into 'master'

Frame free fix

Closes #12

See merge request !13
parents 3b63f6c0 fca6f02d
Pipeline #24447 passed with stages
in 14 minutes and 40 seconds
......@@ -472,10 +472,9 @@ boost::shared_ptr<AVStream> bob::io::video::make_stream(
}
static void deallocate_frame(AVFrame* f) {
if (f) {
if (f->data[0]) av_free(f->data[0]);
av_free(f);
}
if (f->data[0]) av_freep(&f->data[0]);
av_frame_unref(f);
av_frame_free(&f);
}
boost::shared_ptr<AVFrame>
......@@ -496,7 +495,7 @@ bob::io::video::make_frame(const std::string& filename,
int ok = av_image_alloc(retval->data, retval->linesize, codec->width, codec->height, codec->pix_fmt, 1);
if (ok < 0) {
av_free(retval);
av_frame_free(&retval);
boost::format m("bob::io::video::av_image_alloc(data, linesize, width=%d, height=%d, 1) failed: cannot allocate frame/picture buffer start reading or writing video file `%s'");
m % codec->width % codec->height % filename;
throw std::runtime_error(m.str());
......@@ -506,7 +505,7 @@ bob::io::video::make_frame(const std::string& filename,
}
static void deallocate_empty_frame(AVFrame* f) {
if (f) av_free(f);
av_frame_free(&f);
}
boost::shared_ptr<AVFrame> bob::io::video::make_empty_frame(const std::string& filename) {
......
......@@ -92,6 +92,33 @@ def test_video_reader_attributes():
assert isinstance(iv.info, str)
def test_memory_leak():
import psutil
import tempfile
import gc
from . import reader
from bob.io.base import save
my_video = numpy.random.random_integers(0, 255, (10, 3, 256 * 4, 256 * 4))
with tempfile.NamedTemporaryFile(suffix='.avi') as f:
save(my_video.astype('uint8'), f.name)
del my_video
gc.collect()
for i in range(20):
vd = reader(f.name)
for frame in vd:
pass
del frame
del vd
gc.collect()
if i == 0:
first = psutil.virtual_memory().used
last = psutil.virtual_memory().used
assert (last - first) / first < 0.003, "Looks like we have a memory leak!"
def write_unicode_temp_file():
prefix = 'bobtest_straße_'
......
......@@ -58,6 +58,7 @@ test:
- coverage
- sphinx
- sphinx_rtd_theme
- psutil
about:
home: https://www.idiap.ch/software/bob/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment