mirror of
https://frontier.innolan.net/rainlance/c-ares.git
synced 2025-10-06 10:52:20 +00:00
api: Allow injection of user-specified malloc/free functions
Add a new ares_library_init_mem() initialization function for the library which allows the library user to specify their own malloc, realloc & free equivalents for use library-wide. Store these function pointers in library-wide global variables, defaulting to libc's malloc(), realloc() and free(). Change all calls to malloc, realloc and free to use the function pointer instead. Also ensure that ares_strdup() is always available (even if the local environment includes strdup(3)), and change the library code to always use it. Convert calls to calloc() to use ares_malloc() + memset
This commit is contained in:
@ -22,6 +22,7 @@ ares_library_init \- c-ares library initialization
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_library_init(int \fIflags\fP)
|
||||
.B int ares_library_init_mem(int \fIflags\fP, void *(*\fIamalloc\fP)(size_t), void (*\fIafree\fP)(void *))
|
||||
.PP
|
||||
.B cc file.c -lcares
|
||||
.fi
|
||||
@ -51,6 +52,12 @@ ORing the values together. In normal operation you should specify
|
||||
\fIARES_LIB_INIT_ALL\fP. Don't use any other value unless you are
|
||||
familiar with it and trying to control some internal c-ares feature.
|
||||
.PP
|
||||
The
|
||||
.B ares_library_init_mem
|
||||
function allows the caller to provide memory management
|
||||
functions that the c-ares library will be use instead of \fImalloc(3)\fP and
|
||||
\fIfree(3)\fP.
|
||||
.PP
|
||||
.B This function is not thread safe.
|
||||
You have to call it once the program has started, but this call must be done
|
||||
before the program starts any other thread. This is required to avoid
|
||||
|
Reference in New Issue
Block a user