valgrind invalid read of size 4, where is the error?
I'm new with valgrind and I'm trying to use it for memory leaks and other memory problems. In my program I have defined the following class
class LM_EXPORT LdpElement : public Visitable, virtual public RefCounted,
public NodeInTree<LdpElement>
{
protected:
ELdpElement m_type; // the element type
std:开发者_运维问答:string m_name; // for composite: element name
std::string m_value; // for simple: the element value
bool m_fSimple; // true for simple elements
int m_numLine; // file line in which the element starts or 0
long m_id; // for composite: element ID (0..n)
ImoObj* m_pImo;
LdpElement();
public:
virtual ~LdpElement();
//getters and setters
...
inline ImoObj* get_imo() { return m_pImo; }
Valgrind is complaining in this last line "invalid read of size 4". Why? Where is the memory problem in returning the pointer?
Perhaps m_pImo
isn't initialized and valgrind doesn't like that? Does the implementation of your constructor have an initialization list that initializes m_pImo
?
At a high very level, and not necessarily always the cause, I have seen that sometimes Valgrind will complain so when your final (debug) binary (executable) has more than one symbol in it (when linker option is set to be false for "dead code stripping").
I hope this will help others in future. I just discovered this after wasting 2 hours on it. :(
精彩评论