CvRTrees crashes on destructor when making an object copy (Bug #2835)
Description
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:
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; }
Output from GDB
Program received signal SIGSEGV, Segmentation fault. 0x00007ffff774dc4f in CvRTrees::clear() ()
Associated revisions
Merge pull request #2835 from ilya-lavrenov:defects
History
Updated by Vladislav Vinogradov almost 12 years ago
- 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
Updated by Vladislav Vinogradov almost 12 years ago
CvRTrees
doesn't have appropriate copying constructor and assignment operator.
- Category set to ml
- Assignee set to Maria Dimashova
Updated by Maksim Shabunin over 9 years ago
Issue has been transferred to GitHub: https://github.com/Itseez/opencv/issues/4514