Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

unix,win: Make uv_freeaddrinfo to clean up addrinfo

Fixes #196
  • Loading branch information...
erickt authored and ry committed Sep 22, 2011
1 parent 7ce34f2 commit 7e8645d10146c0ef0035f88f13b185e6022896e5
Showing with 23 additions and 6 deletions.
  1. +6 −2 include/uv.h
  2. +5 −2 src/unix/core.c
  3. +1 −0 src/unix/darwin.c
  4. +7 −2 src/win/getaddrinfo.c
  5. +2 −0 test/benchmark-getaddrinfo.c
  6. +2 −0 test/test-getaddrinfo.c
@@ -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. */
@@ -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)
@@ -19,6 +19,7 @@
*/

#include "uv.h"
#include "internal.h"

#include <assert.h>
#include <stdint.h>
@@ -216,12 +216,17 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* handle,
/* 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);
}


@@ -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);
}


@@ -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++;
}

0 comments on commit 7e8645d

Please sign in to comment.
You can’t perform that action at this time.