1
0
mirror of https://frontier.innolan.net/rainlance/c-ares.git synced 2025-10-05 23:59:35 +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:
David Drysdale
2015-09-29 10:12:25 +01:00
parent d493e9b17c
commit f1bcfa1122
35 changed files with 352 additions and 309 deletions

View File

@ -74,7 +74,7 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
if (nlen.sig < 0)
return ARES_EBADNAME;
*s = malloc(nlen.uns + 1);
*s = ares_malloc(nlen.uns + 1);
if (!*s)
return ARES_ENOMEM;
q = *s;