|| Nghia Ho on 2013-02-26 09:03
|| Priority: Normal
|| Affected: branch '2.4'
|| Category: ml
|| Tracker: Bug
|| Difficulty: None
|| PR:
|| Platform: None / None
CvRTrees crashes on destructor when making an object copy
CvRTrees crashes on destruction if a copy variable of it is made. My guess is that they point to the same region of memory, instead of allocating new memory in a deep copy manner, and crashes when the two objects try to release the same memory. Here is a sample code that will cause the crash:
<pre>
int main()
{
CvRTrees forest;
// Generate some data for training, the values are not important
cv::Mat training(100, 2, CV_32F);
cv::Mat labels(100, 1, CV_32S);
for(int i=0; i < 100; i++) {
training.at<float>(i,0) = rand()/(1.0+RAND_MAX);
training.at<float>(i,1) = rand()/(1.0+RAND_MAX);
if(i % 2 == 0) {
labels.at<int>(i) = 1;
}
else {
labels.at<int>(i) = 0;
}
}
forest.train(training, CV_ROW_SAMPLE, labels);
CvRTrees copy_forest = forest;
return 0;
}
</pre>
Output from GDB
<pre>
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff774dc4f in CvRTrees::clear() ()
</pre>
History
Vladislav Vinogradov on 2013-04-01 09:14
- Description changed from CvRTrees crashes on destruction if a copy
variable of it is made. My guess is... to CvRTrees crashes on
destruction if a copy variable of it is made. My guess is... More
Vladislav Vinogradov on 2013-04-01 09:30
@CvRTrees@ doesn't have appropriate copying constructor and assignment operator.
- Assignee set to Maria Dimashova
- Category set to ml
It seems that CvRTrees copy_forest = forest; is not a deep copy, thus share some pointers. One release first, the other release failed and cause memory crash.
Transferred from http://code.opencv.org/issues/2835
CvRTrees crashes on destructor when making an object copy
History
Vladislav Vinogradov on 2013-04-01 09:14
Vladislav Vinogradov on 2013-04-01 09:30