[R-pkg-devel] Valgrind warning on saveRDS, about object in external pointer

David Cortes d@v|d@corte@@r|ver@ @end|ng |rom gm@||@com
Wed Jul 8 18:23:41 CEST 2020


Hello,

I am currently getting a valgrind warning in a package that I’ve
developed, which occurs on a call to R’s ‘saveRDS’, and I am having a
very hard time trying to figure out what went wrong:
https://www.stats.ox.ac.uk/pub/bdr/memtests/valgrind/isotree/isotree-Ex.Rout

In more detail:
- The package creates a C++ struct which it accesses through the
external pointer system (Rcpp::Xptr).
- The warning is about an un-initialized value allocated in a call to
C++ std::vector::reserve, which is called on a C++ vector member of the
struct in the external pointer.
- The warning occurs on a call to R’s ‘saveRDS’.

I had the idea  that ‘saveRDS’ wouldn’t do anything about external
pointers in an S3 object, and thus I am wondering why exactly does the
warning occur in ‘saveRDS’.

Other than the external pointer, the C++ object is also serialized into
an R raw vector using the Cereal library (which occurs in an earlier R
command, before the problematic ‘saveRDS’), and this vector is part of
the objects that get serialized in the call to R’s ‘saveRDS’, but as
far as I know, it should not possible to get such a warning about the
original object after those bytes were copied over and only the new
copied bytes are accessed.

Any help is appreciated.

Sincerely,
David Cortes



More information about the R-package-devel mailing list