Memory management rules for AzureTLS CFFI
mainBecause this is a C FFI, manual memory management is critical to prevent leaks. The library follows a strict ownership model where the caller is responsible for freeing memory allocated by the library.
Cleanup Checklist
- Responses: Call
azuretls_free_response(resp)for everyCFfiResponse*returned byazuretls_session_do. - Strings: Call
azuretls_free_string(str)for anychar*returned by utility functions (likeazuretls_versionor error messages from fingerprinting/proxy functions). - Sessions: Call
azuretls_session_close(session_id)to close a session. - Library: Call
azuretls_cleanup()once at the very end of your program execution. - Initialization: Call
azuretls_init()once at the start of your program.
// Example of a memory-safe pattern
CFfiResponse* response = azuretls_session_do(session, request);
if (response) {
// Use response...
azuretls_free_response(response);
}
char* error = azuretls_session_apply_ja3(session, ja3, navigator);
if (error) {
printf("Error: %s\n", error);
azuretls_free_string(error);
}