mirror of
https://frontier.innolan.net/rainlance/c-ares.git
synced 2025-10-05 14:59:30 +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:
@ -163,7 +163,7 @@ void ares_getnameinfo(ares_channel channel, const struct sockaddr *sa,
|
||||
/* This is where a DNS lookup becomes necessary */
|
||||
else
|
||||
{
|
||||
niquery = malloc(sizeof(struct nameinfo_query));
|
||||
niquery = ares_malloc(sizeof(struct nameinfo_query));
|
||||
if (!niquery)
|
||||
{
|
||||
callback(arg, ARES_ENOMEM, 0, NULL, NULL);
|
||||
@ -234,7 +234,7 @@ static void nameinfo_callback(void *arg, int status, int timeouts,
|
||||
niquery->callback(niquery->arg, ARES_SUCCESS, niquery->timeouts,
|
||||
(char *)(host->h_name),
|
||||
service);
|
||||
free(niquery);
|
||||
ares_free(niquery);
|
||||
return;
|
||||
}
|
||||
/* We couldn't find the host, but it's OK, we can use the IP */
|
||||
@ -265,11 +265,11 @@ static void nameinfo_callback(void *arg, int status, int timeouts,
|
||||
}
|
||||
niquery->callback(niquery->arg, ARES_SUCCESS, niquery->timeouts, ipbuf,
|
||||
service);
|
||||
free(niquery);
|
||||
ares_free(niquery);
|
||||
return;
|
||||
}
|
||||
niquery->callback(niquery->arg, status, niquery->timeouts, NULL, NULL);
|
||||
free(niquery);
|
||||
ares_free(niquery);
|
||||
}
|
||||
|
||||
static char *lookup_service(unsigned short port, int flags,
|
||||
|
Reference in New Issue
Block a user