strange behavior with malloc and free
Ferhat Kurtulmuş
aferust at gmail.com
Fri Oct 11 10:37:02 UTC 2019
Platform: windows
Compiler version: ldc2-1.14.0-windows-x64 or
ldc2-1.17.0-windows-x64
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?
code:
```
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;
free(a);
printf("%d - %d \n", a[0], a[1]); // data is still accessible!
return 0;
}
```
More information about the digitalmars-d-ldc
mailing list