Error on destruction of boost::shared_ptr

I have an stl vector of boost::shared_ptr's declared like so:
vector< shared_ptr<delim_list> > row_data;

delim_list is a custom class encapsulating a vector of strings.

The container is filled like this:
1
2
shared_ptr<delim_list> insert_list(new delim_list(line, ','));
row_data.push_back(insert_list);


When the row_data vector goes out of scope there is a access memory reading violation thrown from the std::string library.

I am using VS2005 and am quite at a loss. The code worked when I was using raw pointers, but am now trying to use smart pointers to save time and gain security.

Thanks,
Ian
It might be unrelated to boost, vector, or string. You might have heap corruption somewhere else in the program.

Are you stepping out of bounds somewhere? Doing any pointer math? Deferencing any arrays?
If I was stepping out of bounds, wouldn't it throw an exception while it the object was being constructed and active? It only throws the error when the object containing the smart_ptr destructs. And no, I'm not doing any pointer math or dereferencing arrays. Here is more of the code.

Declaration of the delim_list class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class delim_list
	{
	private:
		char delimiter;
		vector<string> delim_vec;
		string delim_str;
	public:
		delim_list(const string& str, char delim);
		delim_list(vector<string>& vec, char delim);
		delim_list(char delim);
		const string& to_string(){return delim_str;}
		const vector<string>& to_vector(){return delim_vec;}
		void push_back(const string& str);
	};


And here is the code that loads the vector:
1
2
3
4
5
6
7
8
9
10
11
12
void CSV_File::load_data(ifstream& csv_file)
	{
		string line;
		string cell;
		unsigned int j;
		while (getline(csv_file,line))
		{
		        stringstream line_stream(line);
		        counted_ptr<delim_list> insert_list(new delim_list(line, ','));
			row_data.push_back(insert_list);
                }
         }


Nothing really happens in my test code between construction and destruction. It basically declares a CSV_File object, which calls that load_data method and then lets it go out of scope.



It looks like I misplaced the location of the error, but its still puzzling. I have a std::auto_ptr to that delim_list class that I declare as a class variable and set during construction. But it is inaccessible after that.

The part of the constructor that sets it looks like this.
1
2
3
4
5
6
7
8
9
//variables line and cell are local to the constructor
string line;
string cell;
getline(csv_file, line);

//load the line into a string stream
stringstream line_stream(line);

header = new delim_list(line, ',');

When I call the to_string method (posted earlier) of the delim_list object referenced by the auto_ptr, I get access memory violations. This same problem causes the code to throw an error when the auto_ptr goes out of scope.
Topic archived. No new replies allowed.