Eric Berger
2018-Mar-14 12:23 UTC
[R] R crashing with a segmentation fault: how to locate the cause
I have a littler script which is crashing with a segmentation fault. I tried to find out why by running it through valgrind, which produced the output below. I am not sure how to proceed from here (other than binary search with print statements). Any help would be appreciated. Thanks, Eric ==12589== Invalid read of size 1 ==12589== at 0x4C2F1B1: strcmp (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==12589== by 0x4F71AC1: Rf_inherits (in /usr/lib/R/lib/libR.so) ==12589== by 0x11AFED3A: dplyr::subset_visitor_vector(SEXPREC*) (subset_visitor_impl.h:51) ==12589== by 0x11AFF58C: dplyr::subset_visitor(SEXPREC*, dplyr::SymbolString const&) (subset_visitor_impl.h:21) ==12589== by 0x11AFEC18: dplyr::DataFrameSubsetVisitors::DataFrameSubsetVisitors(Rcpp::DataFrame_Impl<Rcpp::PreserveStorage> const&) (DataFrameSubsetVisitors.h:33) ==12589== by 0x11B1F773: subset<Rcpp::Vector<10, Rcpp::PreserveStorage>> (DataFrameSubsetVisitors.h:120)==12589== by 0x11B1F773: filter_ungrouped(Rcpp::DataFrame_Impl<Rcpp::PreserveStorage>, dplyr::NamedQuosure const&) (filter.cpp:89) ==12589== by 0x11B1FD89: filter_impl(Rcpp::DataFrame_Impl<Rcpp::PreserveStorage>, dplyr::NamedQuosure) (filter.cpp:106) ==12589== by 0x11AD45CB: _dplyr_filter_impl (RcppExports.cpp:192) ==12589== by 0x4F0DBAC: ??? (in /usr/lib/R/lib/libR.so) ==12589== by 0x4F50E50: Rf_eval (in /usr/lib/R/lib/libR.so) ==12589== by 0x4F534FF: ??? (in /usr/lib/R/lib/libR.so) ==12589== by 0x4F50C28: Rf_eval (in /usr/lib/R/lib/libR.so) ==12589== Address 0x2c is not stack'd, malloc'd or (recently) free'd ==12589===12589===12589== Process terminating with default action of signal 11 (SIGSEGV) ==12589== Access not within mapped region at address 0x2C ==12589== at 0x4C2F1B1: strcmp (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==12589== by 0x4F71AC1: Rf_inherits (in /usr/lib/R/lib/libR.so) ==12589== by 0x11AFED3A: dplyr::subset_visitor_vector(SEXPREC*) (subset_visitor_impl.h:51) ==12589== by 0x11AFF58C: dplyr::subset_visitor(SEXPREC*, dplyr::SymbolString const&) (subset_visitor_impl.h:21) ==12589== by 0x11AFEC18: dplyr::DataFrameSubsetVisitors::DataFrameSubsetVisitors(Rcpp::DataFrame_Impl<Rcpp::PreserveStorage> const&) (DataFrameSubsetVisitors.h:33) ==12589== by 0x11B1F773: subset<Rcpp::Vector<10, Rcpp::PreserveStorage>> (DataFrameSubsetVisitors.h:120)==12589== by 0x11B1F773: filter_ungrouped(Rcpp::DataFrame_Impl<Rcpp::PreserveStorage>, dplyr::NamedQuosure const&) (filter.cpp:89) ==12589== by 0x11B1FD89: filter_impl(Rcpp::DataFrame_Impl<Rcpp::PreserveStorage>, dplyr::NamedQuosure) (filter.cpp:106) ==12589== by 0x11AD45CB: _dplyr_filter_impl (RcppExports.cpp:192) ==12589== by 0x4F0DBAC: ??? (in /usr/lib/R/lib/libR.so) ==12589== by 0x4F50E50: Rf_eval (in /usr/lib/R/lib/libR.so) ==12589== by 0x4F534FF: ??? (in /usr/lib/R/lib/libR.so) ==12589== by 0x4F50C28: Rf_eval (in /usr/lib/R/lib/libR.so) ==12589== If you believe this happened as a result of a stack ==12589== overflow in your program's main thread (unlikely but ==12589== possible), you can try to increase the size of the ==12589== main thread stack using the --main-stacksize= flag. ==12589== The main thread stack size used in this run was 8388608. ==12589===12589== HEAP SUMMARY: ==12589== in use at exit: 224,025,975 bytes in 111,522 blocks ==12589== total heap usage: 1,104,400 allocs, 992,878 frees, 625,925,991 bytes allocated ==12589===12589== LEAK SUMMARY: ==12589== definitely lost: 0 bytes in 0 blocks ==12589== indirectly lost: 0 bytes in 0 blocks ==12589== possibly lost: 18,724 bytes in 47 blocks ==12589== still reachable: 224,007,251 bytes in 111,475 blocks ==12589== suppressed: 0 bytes in 0 blocks ==12589== Rerun with --leak-check=full to see details of leaked memory ==12589===12589== For counts of detected and suppressed errors, rerun with: -v ==12589== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) Segmentation fault (core dumped) [[alternative HTML version deleted]]