unix,win: Make uv_freeaddrinfo to clean up addrinfo

Fixes #196
This commit is contained in:
Erick Tryzelaar 2011-09-22 14:28:44 -07:00 committed by Ryan Dahl
parent 7ce34f2ada
commit 7e8645d101
6 changed files with 23 additions and 6 deletions

View File

@ -807,8 +807,10 @@ struct uv_getaddrinfo_s {
*
* Return code 0 means that request is accepted and callback will be called
* with result. Other return codes mean that there will not be a callback.
* Input arguments may be released after return from this call. Callback
* must not call freeaddrinfo.
* Input arguments may be released after return from this call.
*
* uv_freeaddrinfo() must be called after completion to free the addrinfo
* structure.
*/
int uv_getaddrinfo(uv_loop_t*,
uv_getaddrinfo_t* handle,
@ -817,6 +819,8 @@ struct uv_getaddrinfo_s {
const char* service,
const struct addrinfo* hints);
void uv_freeaddrinfo(struct addrinfo* ai);
/* uv_spawn() options */
typedef struct uv_process_options_s {
uv_exit_cb exit_cb; /* Called after the process exits. */

View File

@ -600,8 +600,6 @@ static int uv_getaddrinfo_done(eio_req* req) {
handle->cb(handle, handle->retcode, res);
freeaddrinfo(res);
return 0;
}
@ -668,6 +666,11 @@ int uv_getaddrinfo(uv_loop_t* loop,
}
void uv_freeaddrinfo(struct addrinfo* ai) {
freeaddrinfo(ai);
}
/* Open a socket in non-blocking close-on-exec mode, atomically if possible. */
int uv__socket(int domain, int type, int protocol) {
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)

View File

@ -19,6 +19,7 @@
*/
#include "uv.h"
#include "internal.h"
#include <assert.h>
#include <stdint.h>

View File

@ -216,12 +216,17 @@ complete:
/* finally do callback with converted result */
handle->getaddrinfo_cb(handle, uv_ret, (struct addrinfo*)alloc_ptr);
uv_unref(loop);
}
void uv_freeaddrinfo(struct addrinfo* ai) {
char* alloc_ptr = (char*)ai;
/* release copied result memory */
if (alloc_ptr != NULL) {
free(alloc_ptr);
}
uv_unref(loop);
}

View File

@ -52,6 +52,8 @@ static void getaddrinfo_cb(uv_getaddrinfo_t* handle, int status,
if (calls_initiated < TOTAL_CALLS) {
getaddrinfo_initiate(handle);
}
uv_freeaddrinfo(res);
}

View File

@ -45,6 +45,7 @@ static void getaddrinfo_basic_cb(uv_getaddrinfo_t* handle,
ASSERT(handle == getaddrinfo_handle);
getaddrinfo_cbs++;
free(handle);
uv_freeaddrinfo(res);
}
@ -65,6 +66,7 @@ static void getaddrinfo_cuncurrent_cb(uv_getaddrinfo_t* handle,
ASSERT (i < CONCURRENT_COUNT);
free(data);
uv_freeaddrinfo(res);
getaddrinfo_cbs++;
}