STL list memory leak?

Started by
2 comments, last by polyfrag 10 years, 4 months ago

If I don't call clear(); on the list before I assign it something else, there's a memory leak.



	towrite->brushes.clear();
	towrite->brushes = g_edmap.m_brush;

I tried reproducing the problem with lists of a simple dummy class but it doesn't leak memory like the code above.

The variables above are of type list<EdBrush>.

Any ideas why?


class EdBrush
{
public:
	int m_nsides;
	EdBrushSide* m_sides;
	int m_nsharedv;
	Vec3f* m_sharedv;	//shared vertices array
	int m_texture;	//used to determine brush attributes
	EdDoor* m_door;
	
	EdBrush& operator=(const EdBrush& original);
	EdBrush(const EdBrush& original);
	EdBrush();
	~EdBrush();
	void add(EdBrushSide b);
	void setsides(int nsides, EdBrushSide* sides);
	void copysides(int* nsides, EdBrushSide** sides);
	void removeside(int i);
	void collapse();
	void remaptex();
	Vec3f traceray(Vec3f line[]);
	void prunev(bool* invalidv);
	void moveto(Vec3f newp);
};
Advertisement

Do your assignment overload make sure to delete any memory already allocated by the object you assign to?

If you don't, that could be your problem.

Your assignment operator probably has a bug in it.

You are correct.

This topic is closed to new replies.

Advertisement