【发布时间】:2010-10-02 17:21:15
【问题描述】:
我是 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; }
Valgrind 在最后一行抱怨“无效读取大小为 4”。为什么?返回指针的内存问题在哪里?
【问题讨论】:
-
如果没有 actual valgrind 输出,您的问题将无法回答。问题肯定不是在最后一行,而是在其他地方。
-
你是对的。解决其他内存问题后问题消失。很抱歉没有早点回答。我昨天看到了你的答案,然后回来尝试解决 Valgrid 问题。你的建议是解决这个问题的关键。谢谢。
-
这是个好问题,但没有答案。
标签: memory-leaks valgrind