Proper way to change a cached shared pointer

I have a class which is containing a shared_ptr to data. This class
parses in a XML file and populates the data based upon the contents.
There is a memory problem in this file where I reset the shared_ptr.
class Graph;
class Parser {
public:
boost::shared_ptr<Graph>
parse ( std::string filename,
std::string directory )
{
// Line 110 Formula_Parser.cpp
m_graph.reset ( new Graph() );
... parse file ...
return m_graph;
}
private
boost::shared_ptr<Graph> m_graph;
};
The error I am getting is saying that the problem appears to be in the
==28769== by 0x4154024: libreverse::api::Reverse::execute(std::string const&, unsigned const&, unsigned const&) (Reverse.cpp:128)
==28769== by 0x8055869: main (reverse.cpp:50)
==28769== Address 0x4389BC0 is 8 bytes inside a block of size 60 alloc'd
==28769== at 0x4005BA5: operator new(unsigned) (vg_replace_malloc.c:163)
==28769== by 0x41968E1: libreverse::infrastructure::Formula_Parser::get_Graph(std::string, std::string) (Formula_Parser.cpp:110)
==28769== by 0x419351E: libreverse::infrastructure::Configurator::get_Graph(unsigned, unsigned) (Configurator.cpp:110)
==28769== by 0x4153FBC: libreverse::api::Reverse::execute(std::string const&, unsigned const&, unsigned const&) (Reverse.cpp:115)
==28769== by 0x8055869: main (reverse.cpp:50)
==28769==
==28769== Uninitialised byte(s) found during client check request
==28769== at 0x4161176: libreverse::api::Reverse_Impl::print_Graph(libreverse::infrastructure::Component_Graph const&, std::string) const (Reverse_Impl.cpp:184)
==28769== by 0x4161D96: libreverse::api::Reverse_Impl::execute_Input_Section(boost::shared_ptr

Stephen Torri wrote:
I have a class which is containing a shared_ptr to data. This class parses in a XML file and populates the data based upon the contents. There is a memory problem in this file where I reset the shared_ptr.
Valgrind appears to claim that the contents of 0x4389BC0 are not initialized. It then remarks that
Address 0x4389BC0 is 8 bytes inside a block of size 60 alloc'd
by 0x41968E1: libreverse::infrastructure::Formula_Parser::get_Graph(std::string, std::string) (Formula_Parser.cpp:110)
Line 110 seems correct, but the part of the Graph object at offset 8 is never initialized for some reason, if I read Valgrind's output correctly.

On Wed, 2007-04-04 at 04:33 +0300, Peter Dimov wrote:
Address 0x4389BC0 is 8 bytes inside a block of size 60 alloc'd
by 0x41968E1: libreverse::infrastructure::Formula_Parser::get_Graph(std::string, std::string) (Formula_Parser.cpp:110)
Line 110 seems correct, but the part of the Graph object at offset 8 is never initialized for some reason, if I read Valgrind's output correctly.
All that Graph object has is a Graph_t object and a IdVertexMap_t
object. They are part of object.
class Graph {
public:
typedef property< vertex_index_t,
uint32_t,
property< vertex_name_t,
boost::shared_ptr<Component> > >
VertexProperty_t;
typedef adjacency_list
participants (2)
-
Peter Dimov
-
Stephen Torri