Memory leaks valgrind大小为4的读取无效,错误在哪里?

Memory leaks valgrind大小为4的读取无效,错误在哪里?,memory-leaks,valgrind,Memory Leaks,Valgrind,我是valgrind的新手,我试图用它来解决内存泄漏和其他内存问题。在我的程序中,我定义了以下类 class LM_EXPORT LdpElement : public Visitable, virtual public RefCounted, public NodeInTree<LdpElement> { protected: ELdpElement m_type; // the element type

我是valgrind的新手,我试图用它来解决内存泄漏和其他内存问题。在我的程序中,我定义了以下类

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; }
类LM_导出元素:公共可访问,虚拟公共引用, 公共节点入口 { 受保护的: ELdpElement m_type;//元素类型 std::string m_name;//复合:元素名 std::string m_value;//对于简单:元素值 bool m_fSimple;//对于简单元素为true int m_numLine;//元素开始的文件行或0 长m_id;//对于复合:元素id(0..n) ImoObj*m_pImo; ldp元素(); 公众: 虚拟元素(); //接球手和接球手 ... 内联ImoObj*get_imo(){return m_pImo;}
Valgrind在最后一行抱怨“大小为4的读取无效”。为什么?返回指针时内存问题在哪里?

也许
m\u pImo
没有初始化,valgrind不喜欢这样做?构造函数的实现是否有一个初始化列表,可以在非常高的级别上初始化
m\u pImo

,不一定总是原因,我已经看到有时当您的最终(调试)二进制文件(可执行文件)中有多个符号时(当链接器选项设置为“死代码剥离”为false时),algrind将发出抱怨


我希望这将有助于其他人在未来。我刚刚发现这一点后,浪费了2个小时在它上(

如果没有实际的valgrind输出,您的问题是不可能回答的。问题肯定不在最后一行,而是在其他地方。您是对的。在解决其他内存问题后,问题消失了。很抱歉,之前没有回答。我昨天看到了您的答案,然后返回尝试解决Valgrid问题。您的建议是k谢谢你。这是一个好问题,但没有答案。返回未初始化的值不会触发valgrind错误。请不要给出虚假的答案。谢谢你提供的信息。现在每个不知道的人都学到了一些新东西。不过,我不会不发布基于合理假设的建议例如未初始化的数据。这就是向上/向下投票的目的。如果我的建议错误到可能有害,我将删除它。