strange behavior with malloc and free

Ferhat Kurtulmuş aferust at
Fri Oct 11 10:37:02 UTC 2019

Platform: windows
Compiler version: ldc2-1.14.0-windows-x64 or 

When I compile and run the following code. values of a[] is still 
accessible after calling free(a) somehow. Using dmd code prints 
some random memory values as expected. Is this a problem with ldc 
or am I lack of some information about ldc?

import core.stdc.stdio;
import core.stdc.stdlib;

int main() @nogc nothrow{

     int* a = cast(int*)malloc(2*int.sizeof);
     a[0] = 1;
     a[1] = 2;


     printf("%d - %d \n", a[0], a[1]); // data is still accessible!

     return 0;

More information about the digitalmars-d-ldc mailing list