MLton and Valgrind

David Hansel <[email protected]> Thu, 01 Mar 2012 16:24:26 -0500
Newsgroups gmane.comp.lang.ml.mlton.devel
Message-ID <[email protected]>
Hi,

I've been trying to use Valgrind (valgrind.org) to try to find out if
there are any memory errors in FFI code called by our MLton program
(this is on Ubuntu 10.04).

Running any MLton compiled program under Valgrind at first gave me a
large number of errors, until I tried compiling with the C codegen
(instead of the native).  After changing that the errors seem to be
gone.

However, after adding FFI code to the MLton program I do occasionally
get memory errors reported by Valgrind, presumably during garbage
collection.  Note that the program runs fine and does not crash (with or
without Valgrind). The errors reported look like this:

==19049== Invalid write of size 1
==19049==    at 0x4027448: memset (mc_replace_strmem.c:602)
==19049==    by 0x805157C: setCardMapAndCrossMap (in /home/hansel/test1)
==19049==  Address 0x467b000 is not stack'd, malloc'd or (recently) free'd

==19049== Invalid read of size 1
==19049==    at 0x4026970: memcpy (mc_replace_strmem.c:497)
==19049==    by 0x805183D: forwardObjptr (in /home/hansel/test1)
==19049==  Address 0x470a5ce is not stack'd, malloc'd or (recently) free'd

I'm not an expert with Valgrind and I guess it is possible that these
are somehow wrongfully detected and there is no problem with MLton
itself.  Has anybody here tried using Valgrind with MLton?  Is there
something that I should be aware of?  Should I just ignore these errors
or are they maybe an indication of something going wrong in MLton?

I can provide some example code which produces the errors mentioned
when running under Valgrind.  For the same code the errors go away if
I remove the FFI functions from the .mlb file (the FFI functions are
not actually called by the code,  it seems that just loading the .so
file creates the problem).

If you are interested, please let me know where I can upload
the (2KB) .zip file.

Best regards,

David

-- 
  ----------------------------------------------------------
  David Hansel
  Reactive Systems, Inc.
  http://www.reactive-systems.com/
  ----------------------------------------------------------

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/