MichaelChirico / r-bugs

A ⚠️read-only⚠️mirror of https://bugs.r-project.org/
20 stars 0 forks source link

[BUGZILLA #14695] segfault after a call to .C #4284

Closed MichaelChirico closed 4 years ago

MichaelChirico commented 4 years ago

I have a C/C++ code and I'm calling a function from that code using .C

I did check for memory leak in my C code using valgrind and the output of that is attached. But when I run the same code from R, I get segfault in older versions immediately. In 2.13.2 I will get an exception when I run gc() right after my R script.

Reproduction steps:

  1. extract the prj.tar.gz
  2. call test.R from the src directory inside the package (source("test.R"). That will compile the C code if the .so file is not up to date.
  3. even call something like gc(), or call test.R again.

To reproduce the valgrind output of the C code itself:

  1. compile the code. To do that you can run the following g++ command within the src directory:

g++ -m64 -I/usr/include/R -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic kbest.cpp

  1. Run the valgrind from the src directory like this:

valgrind --leak-check=full ./a.out ../data/Signs.csv ../data/Pvals.csv 2120000000 2


METADATA

MichaelChirico commented 4 years ago

Created attachment 1235 [details] valgrind log file

The valgrind log file attached.


METADATA

INCLUDED PATCH

MichaelChirico commented 4 years ago

Created attachment 1236 [details] source code

prj.tar.gz source code and R file.


METADATA

INCLUDED PATCH

MichaelChirico commented 4 years ago

R buck tracking system is not there to track bugs in your code! It is also not there to ask others to debug your code. It is there to report bugs in R(!!) - please do read the FAQ 9.

From a cursory glance your code causes obvious buffer overflows in character vectors (you don't reserve any space for the values since you're passing 0-length strings and yet you copy into them) so you should expect crashes. You may want to consider using either .Call (if you are familiar with R) or Rcpp (if you are more familiar with C++).


METADATA

MichaelChirico commented 4 years ago

Do you know anything about the free software / open source community?

Why on earth do you think that just because you are maybe an R developer can be that rude to answer a bug report? Is it that hard for you to navigate through bug reports and set their status? Do you feel something like being raped for each bug you resolve/assign/etc? If that's not the case, so why are you so angry about such a bug?

I think from the report itself it's trivial that this report wasn't my first bug report; neither my first time starting a new environment to develop.

Of course I DID read manuals that YOU provided for R extension developers. Couldn't you think even for a little moment that there might be a problem there? Do you think that you are teaching me how memory allocation works?

What I say, is simply that I read the manuals, and from the most cited provided manual, someone can not conclude such a memory allocation system that you mentioned.

The only feedback from such an answer to a bug is that the R community not only is not that helpful, but also is something that you MUST try to avoid.

Sorry guys, I really didn't mean to be rude; but that was really the best way I could clear your situation for yourselves.

Best wishes, Adrin.


METADATA