Memory leak issue between extern (c) and D function

Ali Çehreli acehreli at yahoo.com
Sat Apr 15 11:30:15 UTC 2023


On 4/13/23 20:50, backtrack wrote:

 >      mystruct* getmystruct()
 >      {
 >          mystruct* mystruct = cast(mystruct*)malloc(mystruct.sizeof);
 >          return mystruct;
 >
 >      }

There must be a corresponding function to do the cleaning:

void freemystruct(mystruct* ptr) {
     free ptr;
}

You have to make sure on the D side that freemystruct() is called once 
for each getmystruct().

I have the following presentation that covers similar concepts:

   https://www.youtube.com/watch?v=FNL-CPX4EuM

I think this point is most relevant:

   https://www.youtube.com/watch?v=FNL-CPX4EuM&t=1833s

Ali



More information about the Digitalmars-d-learn mailing list