valgrind Conditional jump or move depends on uninitialised value(s) , does this indicate memory leak?

我们两清 提交于 2019-11-30 05:20:38

No, it means that you are accessing memory that hasn't been initialized:

int main()
{
     int unitialized;
     std::cout << unitialized << std::endl;
}

would trigger this error.

Slightly more common would be:

struct X 
{
     X() : i(42) { }
  private:
     int i;
     int* forgotten; // oops, not initialized
};

Lastly, this frequently happens with malloc based code, when you don't use memset to clear the whole buffer. So,

  1. malloc a buffer size m
  2. read (e.g. from a socket) n bytes
  3. write m bytes to a file; (m-n) bytes wouldn't have been initialized

It is explained in Valgrind User Manual, in section 4.2.2. Use of uninitialised values:

An uninitialised-value use error is reported when your program uses a value which hasn't been initialised -- in other words, is undefined.

...

It is important to understand that your program can copy around junk (uninitialised) data as much as it likes. Memcheck observes this and keeps track of the data, but does not complain. A complaint is issued only when your program attempts to make use of uninitialised data in a way that might affect your program's externally-visible behaviour.

No this does not indicate memory leak directly. However having a conditional jump depending on a non-initialized variable may lead to practically anything. Using uninitialized variables in general invokes undefined behavior.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!