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

Sebastian Meyer @eb@meyer @end|ng |rom |@u@de
Tue Mar 8 18:01:41 CET 2022


Am 08.03.22 um 17:23 schrieb Dirk Eddelbuettel:
> 
> On 8 March 2022 at 18:46, Ivan Krylov wrote:
> | 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
> 
> That is a related problem I did not stress. We can pass debugger arguments to
> the debugger used (here: valgrind) when we call R, but we cannot for R CMD check.
> That should be added.

Not an expert here, but that does seem to be possible, according to WRE 
(Section 4.3.2):

> It is possible to run all the examples, tests and vignettes covered by R CMD check under valgrind by using the option --use-valgrind. If you do this you will need to select the valgrind options some other way, for example by having a ~/.valgrindrc file containing
> 
> --leak-check=full
> --track-origins=yes
> 
> or setting the environment variable VALGRIND_OPTS. As from R 4.2.0, --use-valgrind also uses valgrind when re-building the vignettes. 

Best,

	Sebastian

> 
> | 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.
> 
> I have setup a CI setting using valgrind via R CMD check (and hence lacking
> '--leak-check=full' though one could add a wrapper...) and it is a little
> frustrating to not have it fail.
> 
> But of course it looks like it is a missing feature and we all could work
> towards adding it.  All always that would require cooperation by R Core.
> 
> Dirk
>



More information about the R-package-devel mailing list