Ask Your Question

aecins's profile - activity

2015-01-06 15:04:27 -0600 received badge  Teacher (source)
2014-03-11 12:04:45 -0600 commented answer chamerMatching malloc error
2014-03-11 11:13:05 -0600 answered a question chamerMatching malloc error

I have had a similar issue that might be related to yours. I was trying to run the sample Chmafer matching code from OpenCV (/trunk/opencv/samples/cpp/chamfer.cpp) and I would get the following error:

* glibc detected :double free or corruption (!prev): 0x0000000000745bb0 **

The reason is that in function chamerMatching(img, tpl, results, costs) a template is created and then a reference to it is added inside matcher_ object:

ChamferMatcher::Template template_(templ, (float)templScale);
ChamferMatcher::Matches match_instances = matcher_.matching(template_, img);

As a result when the function returns template_ is destroyed first and then when matcher_ is destroyed it tries to destroy the same template again hence you gen an error.

A quick fix to it is to modify the destructor of Matching() and to comment out the line that deletes templates.

    ~Matching()
    {
        for (size_t i = 0; i<templates.size(); i++) {
            //delete templates[i];
        }
    }

Note, however, that this solution is just a hack that I used to get the demo working. There might be other ways templates can be added to Matching object and those need to be deleted otherwise you will get memory leak.