Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix,win: Make uv_freeaddrinfo to clean up addrinfo
Browse files Browse the repository at this point in the history
Fixes #196
  • Loading branch information
erickt authored and ry committed Sep 23, 2011
1 parent 7ce34f2 commit 7e8645d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
8 changes: 6 additions & 2 deletions include/uv.h
Expand Up @@ -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,
Expand All @@ -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. */
Expand Down
7 changes: 5 additions & 2 deletions src/unix/core.c
Expand Up @@ -600,8 +600,6 @@ static int uv_getaddrinfo_done(eio_req* req) {

handle->cb(handle, handle->retcode, res);

freeaddrinfo(res);

return 0;
}

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/unix/darwin.c
Expand Up @@ -19,6 +19,7 @@
*/

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

#include <assert.h>
#include <stdint.h>
Expand Down
9 changes: 7 additions & 2 deletions src/win/getaddrinfo.c
Expand Up @@ -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);
}


Expand Down
2 changes: 2 additions & 0 deletions test/benchmark-getaddrinfo.c
Expand Up @@ -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);
}


Expand Down
2 changes: 2 additions & 0 deletions test/test-getaddrinfo.c
Expand Up @@ -45,6 +45,7 @@ static void getaddrinfo_basic_cb(uv_getaddrinfo_t* handle,
ASSERT(handle == getaddrinfo_handle);
getaddrinfo_cbs++;
free(handle);
uv_freeaddrinfo(res);
}


Expand All @@ -65,6 +66,7 @@ static void getaddrinfo_cuncurrent_cb(uv_getaddrinfo_t* handle,
ASSERT (i < CONCURRENT_COUNT);

free(data);
uv_freeaddrinfo(res);

getaddrinfo_cbs++;
}
Expand Down

0 comments on commit 7e8645d

Please sign in to comment.