10

I am facing a memory leak problem in the code, while its running, the heap goes on increasing to maximum and i need to restart the service, I ran top command and see that the heap is increasing whenever im invoking a scenario in the service.

I ran the service with valgrind ,

valgrind  --log-file=log-feb19.txt --leak-check=full --show-reachable=yes --track-origins=yes myservice

I donot see any definitely lost or possibly lost blocks while iam running the scenarios but i see a lot of Conditional jump or move depends on uninitialised value(s) errors.

Do these count for a memory leak?

Example of what i am getting:

==27278== Conditional jump or move depends on uninitialised value(s)

==27278==    at 0xC90D91E: xcsFreeMemFn (in /apps/opt/mqm/lib64/libmqmcs_r.so)

........

==27278==  Uninitialised value was created by a heap allocation

==27278==    at 0x4A078B8: malloc (vg_replace_malloc.c:270)

==27278==    by 0xC90E32F: xcsGetMemFn (in /apps/opt/mqm/lib64/libmqmcs_r.so)

Can someone help.

user862833
  • 299
  • 2
  • 5
  • 16
  • have you found the correct answer? if it is, mark one as correct, please. – logoff Feb 20 '13 at 08:03
  • possible duplicate of [pinpointing "conditional jump or move depends on uninitialized value(s)" valgrind message](http://stackoverflow.com/questions/2612447/pinpointing-conditional-jump-or-move-depends-on-uninitialized-values-valgrin) – Victor Sergienko Feb 20 '15 at 15:45

3 Answers3

16

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
sehe
  • 374,641
  • 47
  • 450
  • 633
  • I agree this does not indicate a memory leak but as it invokes undefined behavior it may lead to anything – Ivaylo Strandjev Feb 19 '13 at 08:09
  • Actually, it is more than that, it means that the flow of execution of program might depend on an uninitialized value. – alfC Jul 28 '20 at 03:01
5

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.

logoff
  • 3,347
  • 5
  • 41
  • 58
2

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.

Ivaylo Strandjev
  • 69,226
  • 18
  • 123
  • 176
  • 2
    In C, using an uninitialized object is not undefined behavior per se. It is only UB if the object "could have been declared with `register`" that is if its address is never taken. Reading uninitialized memory through a pointer is perfectly fine (from that POV). It is the branching on such values that valgrind rightly complains about. – Jens Gustedt Feb 19 '13 at 08:19