Memory leak in cv::VideoCapture

Bug #1773803 reported by Jacopo Carravieri
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
opencv (Ubuntu)
New
Undecided
Unassigned

Bug Description

I am developing a custom C++ programs which continuously processes a huge number of short videos, so several instances of cv::VideoCapture are endlessly created and destroyed. I noticed that the memory consumption keeps growing, until after some days the process gets killed by the operating system.

After careful testing I tracked down the memory leak in cv::VideoCapture. Commenting only this object, leaving the rest of the program untouched, with the exception of those parts where this object is used, which are changed so that the job done is as close as possible (ex. using a zero-initialized cv::Mat object instead of a video frame) leads to no memory leak after hours of execution.

This is portion of code where the error occurs:

void procressVideo(boost::filesystem::path name) {
    VideoCapture video(name.string());
    if(!video.isOpened()) {
        return;
    }
    size_t width = video.get(CV_CAP_PROP_FRAME_WIDTH);
    size_t height = video.get(CV_CAP_PROP_FRAME_HEIGHT);
    // Process frames
    Mat prev(height, width, CV_8UC3, Scalar(0));
    Mat frame;
    for(long i = 0; video.read(frame); i++)
    {
        cvtColor(frame, frame, CV_BGR2RGB);
        frame.convertTo(frame, CV_8UC3);
        ...
        ...
        frame.copyTo(prev);
    }
    video.release();
    boost::filesystem::remove(name);
}

ProblemType: Bug
DistroRelease: Ubuntu 18.04
Package: libopencv-videoio3.2 3.2.0+dfsg-4build2
ProcVersionSignature: Ubuntu 4.15.0-22.24-generic 4.15.17
Uname: Linux 4.15.0-22-generic x86_64
ApportVersion: 2.20.9-0ubuntu7
Architecture: amd64
CurrentDesktop: ubuntu:GNOME
Date: Mon May 28 15:02:47 2018
InstallationDate: Installed on 2018-05-24 (3 days ago)
InstallationMedia: Ubuntu 18.04 LTS "Bionic Beaver" - Release amd64 (20180426)
SourcePackage: opencv
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Jacopo Carravieri (lordhawksmoor) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.