Freeing a string (allocated in Ada) in a C function using free()

Viewed 466

I am working on a C-Ada binding application, where I am allocating a new string in Ada side using Interfaces.C.Strings.New_String().

Interfaces.C.Strings already has a procedure Free() to deallocate the memory for string. Since I need to pass this string to a C function using Interfaces.C.Strings.Chars_Ptr:

  1. Is it OK if I deallocate memory for the string in C side using the free() function (declared in stdlib.h)?

  2. Is it safe if I free the memory from C side?

  3. Or I should better free it using the Interfaces.C.Strings.Free() function from Ada side?

2 Answers
Related