Menu

#1131 [php] director uses invalid iterator

closed-accepted
php (58)
5
2011-02-18
2011-02-08
No

in trunk/Lib/php/director.swg there is:
~Director() {
for (swig_ownership_map::iterator i = swig_owner.begin(); i != swig_owner.end(); i++) {
swig_owner.erase(i);
}
}

The i++ after the erase is invalid use of an std::map iterator. The erase invalidates the iterator.

It seems that this code should be written without the loop as:
~Director() {
swig_owner.clear();
}

I have attached a patch.
Thanks
-Cory

Discussion

  • Cory Bennett

    Cory Bennett - 2011-02-08

    patch for trunk/Lib/php/director.swg @ r12441

     
  • Olly Betts

    Olly Betts - 2011-02-18
    • summary: php director uses invalid iterator --> [php] director uses invalid iterator
     
  • Olly Betts

    Olly Betts - 2011-02-18

    Unless I'm missing something, we don't actually need an explicit destructor here at all! The swig_owner member will be destoyed when the object is, and that will call any destructors on objects in the map.

    Testing that change now...

     
  • Olly Betts

    Olly Betts - 2011-02-18
    • status: open --> open-accepted
     
  • Olly Betts

    Olly Betts - 2011-02-18

    That works, so applied in r12469.

     
  • Olly Betts

    Olly Betts - 2011-02-18
    • status: open-accepted --> closed-accepted
     

Log in to post a comment.