[Rd] calloc() vs. R_Calloc()

Tomas Kalibera tom@@@k@||ber@ @end|ng |rom gm@||@com
Thu Apr 7 10:59:49 CEST 2022

On 4/7/22 10:32, Adrian Dușa wrote:
> On Thu, 7 Apr 2022 at 10:32, Tomas Kalibera <tomas.kalibera using gmail.com> 
> wrote:
>     [...]
>     And what are the errors you run into? On which platforms, under what
>     circumstances, etc? It would be much easier to give advice knowing
>     that.
>     In principle, one issue you may run into when switching allocators is
>     that you accidentally end up freeing by a different allocator from
>     the
>     one used to allocate it. It is common on Windows but can in principle
>     happen elsewhere as well.
>     Also by a slightly different heap layout or different allocator
>     implementation you may wake up bugs in the program not seen
>     previously
>     (use after free, invalid memory accesses, etc)
> That is something I do not know yet, since the only information the 
> server gives is this:
> https://builder.r-hub.io/status/original/QCA_3.16.tar.gz-a03b4462b41df37c6284be1d5519e8b3
> I'll probably end up debugging the C code, but since the only 
> difference is using Free() vs free() on exactly the same objects, I 
> suspected a mis-usage of the R commands.
> The same setup passes with no problems on my local MacOS, but the 
> errors still seem to occur on the Windows setup from r-hub.

This is very likely because you are freeing memory allocated by calloc() 
(or something else but not R_Calloc() in your program) using R_Free() or 
memory allocated using R_Calloc() by using free() in your program.
I would recommend checking the source code manually for that.

It is not surprising that the problem doesn't appear on other platforms 
where the allocators happen to be the same.


> Best wishes,
> Adrian
	[[alternative HTML version deleted]]

More information about the R-devel mailing list