Ruby under Valgrind shows a ton of memory errors -- normal?

Hi,

I’m hoping someone who knows MRI internals very well can answer this
one.

I was trying to debug a problem with MRI today using Valgrind, and
noticed when Ruby is run on top of Valgrind, virtually any Ruby program
(even those which work correctly) will display a slew of memory errors.
The errors are mostly “Use of uninitialised value of size 8” and
“Conditional jump or move depends on uninitialised value(s)” (though I
have seen others). The errors come from the code for Ruby’s GC.

Is this normal? Does Ruby’s GC do some fancy things with pointers which
trick Valgrind into thinking it is “using uninitialized values”? Or are
these real bugs?

Thanks, Alex

Alex D. wrote in post #1082916:

Is this normal? Does Ruby’s GC do some fancy things with pointers which
trick Valgrind into thinking it is “using uninitialized values”?

I believe so. This is “conservative garbage collection” - anything on
the stack which looks like a valid object reference is treated as one,
even if it is actually garbage. It means some objects are ‘marked’ as in
use, even if they actually aren’t.

Brian C. wrote in post #1083005:

I believe so. This is “conservative garbage collection” - anything on
the stack which looks like a valid object reference is treated as one,
even if it is actually garbage. It means some objects are ‘marked’ as in
use, even if they actually aren’t.

Thanks for the response. I don’t think this is relevant to the errors
which I mentioned, though.

Valgrind is an x86 emulator which can be used to check a program for
problems like buffer overruns, freeing a pointer twice, using
uninitialized variables, etc. As an example, as it interprets the
program one machine instruction at a time, it watches for instructions
which read memory locations which were not previously written to. When
it executes such an instruction, it prints a warning to STDERR.

Run MRI on top of that emulator, and any Ruby program will result in a
bunch of warnings that the GC is performing computations based on the
values of uninitialized memory.

I’m interested in whether the Ruby core team is aware of this and
whether it is normal. If not, I will dig deeper.

Yukihiro M. wrote in post #1083010:

We are aware of, and this is normal. Attached file makes warning bit
better.

Thanks!!!

BTW, the problem which caused me to use Valgrind in the first place
seems to be fixed in 1.9.3-p194. (I was working on a legacy Rails app
which was running on 1.9.2-p320.)

Hi,

In message “Re: Ruby under Valgrind shows a ton of memory errors –
normal?”
on Tue, 6 Nov 2012 03:41:21 +0900, Alex D. [email protected]
writes:

|I’m interested in whether the Ruby core team is aware of this and
|whether it is normal. If not, I will dig deeper.

We are aware of, and this is normal. Attached file makes warning bit
better.

          matz.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs