Ray Tayek on Thu, 19 Jan 2006 22:49:50 -0600 (CST) |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: [ALACPP] memory leak |
the simple example below works. so i must be going south somewhere. #ifndef LEAK_H_ #define LEAK_H_ #include <iostream> #include <map> using namespace std; enum Direction {n,s,e,w}; class MapSite {}; class Leak { public: Leak(); virtual ~Leak(); MapSite *get(Direction direction) const { map<Direction,MapSite *>::const_iterator i=m.find(direction); return i!=m.end()?i->second:NULL; } MapSite *insert(Direction direction,MapSite *mapSite) { MapSite *rc=NULL;pair<map<Direction,MapSite *>::iterator,bool> p=m.insert(map<Direction,MapSite *>::value_type(direction,mapSite));
if(!p.second) { rc=p.first->second; p.first->second=mapSite; } return rc; } map<Direction,MapSite *> m; }; int main() { new char[100],new char[101],new char[102],new char[103]; // force an error Leak *l=new Leak(); l->insert(n,new MapSite()); l->insert(s,new MapSite()); for(Direction d=n;d<=w;d=(Direction)(d+1)) if(l->get(d)) delete l->get(d); delete l; return 0; } #endif /*LEAK_H_*/ --- vice-chair http://ocjug.org/ _______________________________________________ alacpp mailing list alacpp@xxxxxxxxxxx http://lists.ellipsis.cx/mailman/listinfo/alacpp