views:

57

answers:

1

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?

A: 

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?

Arnold Spence
Returning uninitialized value does *not* trigger valgrind error. Please refrain from giving bogus answers.
Employed Russian
Thanks for the info. Now everyone that didn't know has learned something new. I won't however refrain from posting suggestions that are based on reasonable assumptions such as uninitialized data. That's what up/down votes are for. If my suggestion is ever so wrong that it is potentially harmful, I will delete it.
Arnold Spence