From ru|pb@rr@d@@ @end|ng |rom @@po@pt  Thu Apr  7 17:49:22 2022
From: ru|pb@rr@d@@ @end|ng |rom @@po@pt (Rui Barradas)
Date: Thu, 7 Apr 2022 16:49:22 +0100
Subject: [Rd] calloc() vs. R_Calloc()
In-Reply-To: <edf0b33b-2f4a-6e2a-02d5-55f548326ea2@gmail.com>
References: <CAJ=0CtBMDXf4R0DR40whvXS5i8=KUrPRqbZWC-TWWeU2DfzQjw@mail.gmail.com>
 <f57301d8-c736-34af-29b1-c59d9458b180@gmail.com>
 <CAJ=0CtAnkUtOqhVVzx7wZUYvRjWZig6HrC700hQUZaRqPE7a_A@mail.gmail.com>
 <edf0b33b-2f4a-6e2a-02d5-55f548326ea2@gmail.com>
Message-ID: <30b8bdc2-4897-1971-dbe9-712825e27d1f@sapo.pt>

Hello,

Tomas is right, there are many memory operations allocating with malloc 
and freeing with R_Free:

line: variables - operation

  55: p_pichart - malloc
336: p_pichart - R_Free

236: copy_implicants - malloc
260: copy_implicants - R_Free

240: p_tempic - malloc
262: p_tempic - R_Free


And there are more cases like these. For what I've seen, the frequent 
(unique?) case is malloc/R_Free.

Hope this helps,

Rui Barradas

?s 09:59 de 07/04/2022, Tomas Kalibera escreveu:
> 
> On 4/7/22 10:32, Adrian Du?a wrote:
>> On Thu, 7 Apr 2022 at 10:32, Tomas Kalibera <tomas.kalibera at 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
> Tomas
> 
> 
>>
>> Best wishes,
>> Adrian
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] calloc() vs. R_Calloc()
Rui Barradas