[R-pkg-devel] Failing Valgrind Passing R CMD check

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Tue Mar 8 16:46:13 CET 2022


On Sun, 6 Mar 2022 11:00:43 -0600
Dirk Eddelbuettel <edd using debian.org> wrote:

> ==1485886== LEAK SUMMARY:
> ==1485886==    definitely lost: 32 bytes in 1 blocks

> ==1485886== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0
> from 0)

R CMD check only looks at the exit code of the process.

Valgrind crashes the process on invalid memory access, but doesn't
consider leaks to be errors, unless you turn on --leak-check=full, and
even then still returns the exit code of the child process by default,
i.e. zero:

$ cat leak.c 
#include <stdlib.h>

int main(void) {
        malloc(42);
        return 0;
}
$ cc -o leak -g -O0 leak.c
$ valgrind ./leak; echo exitcode=$?
...
==14675==    definitely lost: 42 bytes in 1 blocks
...
==14675== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
exitcode=0
$ valgrind --leak-check=full ./leak; echo exitcode=$?
...

==14688==    definitely lost: 42 bytes in 1 blocks
...
==14688== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
exitcode=0
$ valgrind --leak-check=full --error-exitcode=42 ./leak; \
 echo exitcode=$?
...
==14729==    definitely lost: 42 bytes in 1 blocks
...
==14729== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
exitcode=42

R CMD check could be patched to run 
R -d 'valgrind --leak-check=full --error-exitcode=255' instead of just
R -d valgrind to produce warnings on Valgrind-detected leaks.

The problem with this approach is the need for Valgrind suppression
files. I've run an interactive example of a pure R package under R -d
'valgrind --leak-check=full --error-exitcode=255' (a relatively fresh
SVN build) and got "definitely lost: 15,744 bytes in 41 blocks", mostly
in plot-related code, allocations originating in Pango and GObject.

-- 
Best regards,
Ivan



More information about the R-package-devel mailing list