Boost logo

Boost Users :

Subject: Re: [Boost-users] [BGL] Free graph - double free or corruption
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2010-01-03 21:04:31


On Mon, 4 Jan 2010, Matthieu BOUSSARD wrote:

> Yes, the planner object contains the graph. Since the graph is declare inside
> the object I don't have to destroy it explicitely. right ?
>
> The following code is one thing I've tried, the first one I tried was to
> iterate on the and freeing the states, but didn't work... So here, first
> romove from the graph and the free the state. If no other solution I'll try
> to switch to boost::shared_ptr<state_t> but I'd like to understand what's
> going on.
> thamk you for your quick answer !
>
> class Sampling_solver{
> public:
> int nbsample;
> Graph g;
> vertex_name_map_t v_name_map ;
> vertex_prop_map_t v_prop_map ;
> edge_weight_map_t e_weight_map;
> edge_name_map_t e_name_map ;
> state_vertex_map_t name_vertex_map;
>
> Sampling_solver(Model *m);
> ~Sampling_solver(){
> graph_traits<Graph>::vertex_iterator vi, vi_end, next;
> tie(vi, vi_end) = vertices(g);
> for (next = vi; vi != vi_end; vi = next) {
> ++next;
> remove_vertex(*vi, g);
> free(v_name_map[*vi]);
> }
> g.clear();
> };

Are you sure the solver object outlives the graph (and all copies of
properties obtained from the graph)? Do you destroy the solver then use
the results of the algorithm (that are state objects destroyed by the
solver's destructor)? In any case, shared_ptr is a much simpler way to
deal with the problem if performance is not critical.

-- Jeremiah Willcock


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net