Skip to content

Instantly share code, notes, and snippets.

@wush978
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wush978/629743109e4aaa762968 to your computer and use it in GitHub Desktop.
Save wush978/629743109e4aaa762968 to your computer and use it in GitHub Desktop.
A Dockerfile to reproduce the detected error by Valgrind
FROM rocker/r-base
WORKDIR /root
RUN Rscript -e "install.packages('Rcpp');Rcpp::Rcpp.package.skeleton('testMemoryLeak')"
RUN apt-get install -y --no-install-recommends valgrind
#
#
# //[[Rcpp::export]]
# void test() {
# std::string msg("test");
# throw std::logic_error(msg);
# }
#
#
WORKDIR /root/testMemoryLeak
RUN echo "//[[Rcpp::export]]" >> src/rcpp_hello_world.cpp && \
echo "void test() {" >> src/rcpp_hello_world.cpp && \
echo " std::string msg(\"test\");" >> src/rcpp_hello_world.cpp && \
echo " throw std::logic_error(msg);" >> src/rcpp_hello_world.cpp && \
echo "}" >> src/rcpp_hello_world.cpp && \
Rscript -e "Rcpp::compileAttributes('.')"
RUN R CMD INSTALL .
RUN echo "library(testMemoryLeak);tryCatch(test(), error = function(e) { })" | R -d "valgrind --tool=memcheck --leak-check=full" --vanilla
==8== Memcheck, a memory error detector
==8== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==8== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==8== Command: /usr/lib/R/bin/exec/R --vanilla
==8==
R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(testMemoryLeak);tryCatch(test(), error = function(e) { })
NULL
>
==8==
==8== HEAP SUMMARY:
==8== in use at exit: 31,602,784 bytes in 15,830 blocks
==8== total heap usage: 39,485 allocs, 23,655 frees, 65,752,608 bytes allocated
==8==
==8== 29 bytes in 1 blocks are possibly lost in loss record 13 of 1,676
==8== at 0x4C29180: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8== by 0xCD97E98: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==8== by 0xCD99814: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==8== by 0xCD99C45: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==8== by 0xCFE8B93: test() (rcpp_hello_world.cpp:16)
==8== by 0xCFE7D8A: testMemoryLeak_test (RcppExports.cpp:28)
==8== by 0x4ECE3A8: ??? (in /usr/lib/R/lib/libR.so)
==8== by 0x4F0F660: ??? (in /usr/lib/R/lib/libR.so)
==8== by 0x4F10F39: ??? (in /usr/lib/R/lib/libR.so)
==8== by 0x4F0F53D: ??? (in /usr/lib/R/lib/libR.so)
==8== by 0x4F12B86: ??? (in /usr/lib/R/lib/libR.so)
==8== by 0x4F0F476: ??? (in /usr/lib/R/lib/libR.so)
==8==
==8== 144 bytes in 1 blocks are possibly lost in loss record 30 of 1,676
==8== at 0x4C28C20: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8== by 0xCD36822: __cxa_allocate_exception (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==8== by 0xCFE8B9D: test() (rcpp_hello_world.cpp:17)
==8== by 0xCFE7D8A: testMemoryLeak_test (RcppExports.cpp:28)
==8== by 0x4ECE3A8: ??? (in /usr/lib/R/lib/libR.so)
==8== by 0x4F0F660: ??? (in /usr/lib/R/lib/libR.so)
==8== by 0x4F10F39: ??? (in /usr/lib/R/lib/libR.so)
==8== by 0x4F0F53D: ??? (in /usr/lib/R/lib/libR.so)
==8== by 0x4F12B86: ??? (in /usr/lib/R/lib/libR.so)
==8== by 0x4F0F476: ??? (in /usr/lib/R/lib/libR.so)
==8== by 0x4F14282: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==8== by 0x4F0F1CD: ??? (in /usr/lib/R/lib/libR.so)
==8==
==8== LEAK SUMMARY:
==8== definitely lost: 0 bytes in 0 blocks
==8== indirectly lost: 0 bytes in 0 blocks
==8== possibly lost: 173 bytes in 2 blocks
==8== still reachable: 31,602,611 bytes in 15,828 blocks
==8== suppressed: 0 bytes in 0 blocks
==8== Reachable blocks (those to which a pointer was found) are not shown.
==8== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==8==
==8== For counts of detected and suppressed errors, rerun with: -v
==8== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment