View Issue Details

IDProjectCategoryView StatusLast Update
0004822ardourbugspublic2020-04-19 20:16
Reporterahurst Assigned Tocth103  
PrioritynormalSeveritymajorReproducibilityhave not tried
Status closedResolutionfixed 
Product Version3.0-beta3 
Target Version3.0 
Summary0004822: Invalidated iterator used
DescriptionMedium impact static analysis bug:

An iterator is invalidated and then subsequently used at libs/ardour/region_factory:623.

Need to keep a copy of next valid iterator before erasing current.
Additional Information618void
619RegionFactory::remove_regions_using_source (boost::shared_ptr<Source> src)
620{
621 Glib::Mutex::Lock lm (region_map_lock);
622
*** Using invalid iterator "i" (on repeating the loop after the events below).
623 for (RegionMap::iterator i = region_map.begin(); i != region_map.end(); ++i) {
*** Condition "i->second->uses_source(boost::shared_ptr<ARDOUR::Source const>(src, boost::detail::sp_empty({})))", taking true branch
624 if (i->second->uses_source (src)) {
*** "erase" invalidates iterator "i".
625 region_map.erase (i);
626 }
*** Jumping back to the beginning of the loop
627 }
628}
TagsNo tags attached.

Activities

2012-04-09 15:11

 

bug_4822 (609 bytes)   
Index: libs/ardour/region_factory.cc
===================================================================
--- libs/ardour/region_factory.cc	(revision 11846)
+++ libs/ardour/region_factory.cc	(working copy)
@@ -619,10 +619,13 @@
 RegionFactory::remove_regions_using_source (boost::shared_ptr<Source> src)
 {
 	Glib::Mutex::Lock lm (region_map_lock);
+	RegionMap::iterator	save;
 
 	for (RegionMap::iterator i = region_map.begin(); i != region_map.end(); ++i) {
+	  save = region_map.upper_bound(i->first);
 		if (i->second->uses_source (src)) {
 			region_map.erase (i);
+			i = save;
                 }
 	}
 }
bug_4822 (609 bytes)   

epitech_user

2012-04-09 15:11

reporter   ~0013096

Here is a patch, but i'm not sure of the correction!

ahurst

2012-04-09 22:27

reporter   ~0013098

Yeah, these are tricky. Two things: you need to increment before erase, so that save doesn't also point to the erased element. Also, the increment inside the for statement mustn't applied to the end() element. A compact solution:

Index: libs/ardour/region_factory.cc
===================================================================
--- libs/ardour/region_factory.cc (revision 11846)
+++ libs/ardour/region_factory.cc (working copy)
@@ -619,10 +619,13 @@
 RegionFactory::remove_regions_using_source (boost::shared_ptr<Source> src)
 {
     Glib::Mutex::Lock lm (region_map_lock);
- for (RegionMap::iterator i = region_map.begin(); i != region_map.end(); ++i) {
+ RegionMap::iterator i = region_map.begin();
+ while(i != region_map.end()) {
         if (i->second->uses_source (src)) {
- region_map.erase(i);
+ region_map.erase(i++);
+ } else {
+ ++i;
         }
     }
 }

cth103

2012-04-11 10:43

administrator   ~0013111

Fixed in SVN 11893.

system

2020-04-19 20:16

developer   ~0023031

Issue has been closed automatically, by Trigger Close Plugin.
Feel free to re-open with additional information if you think the issue is not resolved.

Issue History

Date Modified Username Field Change
2012-04-05 00:30 ahurst New Issue
2012-04-05 01:05 cth103 cost => 0.00
2012-04-05 01:05 cth103 Target Version => 3.0 beta4
2012-04-09 15:11 epitech_user File Added: bug_4822
2012-04-09 15:11 epitech_user Note Added: 0013096
2012-04-09 22:27 ahurst Note Added: 0013098
2012-04-11 10:43 cth103 Note Added: 0013111
2012-04-11 10:43 cth103 Status new => resolved
2012-04-11 10:43 cth103 Resolution open => fixed
2012-04-11 10:43 cth103 Assigned To => cth103
2012-05-23 15:08 cth103 Target Version 3.0 beta4 => 3.0
2020-04-19 20:16 system Note Added: 0023031
2020-04-19 20:16 system Status resolved => closed