Changeset 9412:b83e62d6ab27 in orange


Ignore:
Timestamp:
12/23/11 09:20:07 (2 years ago)
Author:
matija <matija.polajnar@…>
Branch:
default
Convert:
ac163eabc2e2e3ef37e62c5ef3e5b29feb4cc476
Message:

Fix memory corruption on program shutdown in vars.cpp.

Location:
source/orange
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • source/orange/vars.cpp

    r7705 r9412  
    4949#include "vars.ppp" 
    5050 
    51 typedef multimap<string, TVariable *> MMV; 
     51bool mmvDeallocated = 0; 
     52 
     53/* The following class is to be used only for the allVariablesMap variable. 
     54 * It sets a flag after it has been deallocated, so that after program shutdown 
     55 * the deallocated TVariable instances do not try to remove themselves from the 
     56 * map. Besides, this class overrides the non-virtual destructor of STL 
     57 * multimap, so it's not functional if the variable is declared using MMV's 
     58 * supertype! 
     59 */ 
     60class MMV : public multimap<string, TVariable *> { 
     61public: 
     62    ~MMV() { 
     63        mmvDeallocated = 1; 
     64    } 
     65}; 
    5266 
    5367DEFINE_TOrangeVector_classDescription(PVariable, "TVarList", true, ORANGE_API) 
     
    240254    /* When the program shuts down, it may happen that the list is destroyed before 
    241255       the variables. We do nothing in this case. */ 
    242     if (allVariablesMap.size()) { 
     256    if (!mmvDeallocated) { 
    243257        removeVariable(); 
    244258    } 
  • source/orange/vars.hpp

    r7705 r9412  
    5353WRAPPER(Classifier) 
    5454 
     55class MMV; 
    5556 
    5657class ORANGE_API TVariable : public TOrange { 
     
    9697  } 
    9798 
    98   static multimap<string, TVariable *> allVariablesMap; 
     99  static MMV allVariablesMap; 
    99100 
    100101  ~TVariable(); 
Note: See TracChangeset for help on using the changeset viewer.