Re: [Rcpp-devel] Does uncaught c++ exception cause memory leak?

2014-12-29 Thread Kevin Ushey
Hi Wush, Thanks for investigating this, and I would certainly welcome a fix / tweak to the END_RCPP macro to avoid this potential memory leak. However, I am also curious -- where exactly does this memory leak occur, what exactly is being leaked, and why does your modified example avoid it? My bes

Re: [Rcpp-devel] Does uncaught c++ exception cause memory leak?

2014-12-29 Thread Wush Wu
Dear Romain, Dirk, and Qiang, Thanks for Romain's reminder of auto appended catch block, Dirk's explanation of leaks and exception and Qiang's simple example. Now I understand that an uncaught exception in a c++ program might cause memory leak. A SO Q&A ( http://stackoverflow.com/questions/2767789

Re: [Rcpp-devel] Does uncaught c++ exception cause memory leak?

2014-12-29 Thread Qiang Kou
Hi, Wush, It seems that memory leakage has nothing to do with R. Just use your code without R: #include #include int main(int argc, char **argv) { std::string msg = std::string("test"); throw std::logic_error(msg); return 0; } I still get the same leakage information: ==19532==

Re: [Rcpp-devel] Does uncaught c++ exception cause memory leak?

2014-12-29 Thread Dirk Eddelbuettel
PS Here is a better variant that actually leaks: edd@max:/tmp$ cat leak.cpp #include #include #include

Re: [Rcpp-devel] Does uncaught c++ exception cause memory leak?

2014-12-29 Thread Dirk Eddelbuettel
Hi Wush, On 30 December 2014 at 01:28, Wush Wu wrote: | I have a question which is described in the subject. Yes it can. Which is why some C++ coding guidelines prohibit use of exception. Also, Meyers has some good explanations of why you can never throw in destructor: exceptions could get in t

Re: [Rcpp-devel] Does uncaught c++ exception cause memory leak?

2014-12-29 Thread Wush Wu
However, if I manually use a try/catch to enclose the exception, then the valgrind detects no error. It seems that raising R error causes the memory error, is it? 2014-12-30 1:42 GMT+08:00 Romain Francois : > includes ___ Rcpp-devel mailing list Rcpp-d

Re: [Rcpp-devel] Does uncaught c++ exception cause memory leak?

2014-12-29 Thread Romain Francois
Uncaught exception gives you UB. It is however difficult not to catch exceptions if you use Rcpp::export attributes which includes a "catch all and deal with it" part. Romain Envoyé de mon iPhone > Le 29 déc. 2014 à 18:28, Wush Wu a écrit : > > Dear all, > > I have a question which is desc

[Rcpp-devel] Does uncaught c++ exception cause memory leak?

2014-12-29 Thread Wush Wu
Dear all, I have a question which is described in the subject. It is discovered when I use the valgrind to check my package. Because I am not familiar with valgrind, please help me verify that if this is a bug of Rcpp or not. Here is a minimal reproducible example with docker and the log of val