[Rd] custom allocators, Valgrind and uninitialized memory

Andreas Kersting r-deve| @end|ng |rom @ker@t|ng@de
Fri Mar 26 20:48:56 CET 2021

Hi Dirk,

Sure, let me try to explain:

CRAN ran the tests of my package using R which was configured --with-valgrind-instrumentation > 0. Valgrind reported many errors related to the use of supposedly uninitialized memory and the CRAN team asked me to tackle these.

These errors are false positives, because I pass a custom allocator to allocVector3() which hands out memory which is already initialized. However, this memory is explicitly marked for Valgrind as uninitialized by allocVector3(), and I do not initialize it subsequently, so Valgrind complains.

Now I am asking if it is correct that allocVector3() marks memory as uninitialized/undefined, even if it comes from a custom allocator. This is because allocVector3() cannot know if the memory might already by initialized.

If this is the intended behavior of allocVector3(), then I am looking for the proper way to get rid of these false Valgrind errors. So to be able to more easily spot the true ones ...

Which section of _Writing R Extensions_ do you have in mind? I cannot find anything on custom allocators there, but maybe I am using the wrong search terms. No, these object are returned to R and I am not aware that this is a problem / not allowed.

Regards, Andreas

2021-03-26 19:51 GMT+01:00 "Dirk Eddelbuettel" <edd using debian.org>:
> Andreas,
> Can you briefly describe what it is you are trying to do?
> In general, no R package would use valgrind directly; it is an optional
> debugger. Also note _Writing R Extensions_ has a few things to say about how
> memory destined for R object can and cannot be allocated -- I presume your
> custom allocator is only for objects you managed and do not return to R?
> Best, Dirk
> -- 
> https://dirk.eddelbuettel.com | @eddelbuettel | edd using debian.org

More information about the R-devel mailing list