summaryrefslogtreecommitdiff
path: root/deps/uv/src/unix
diff options
context:
space:
mode:
authorSaúl Ibarra Corretgé <saghul@gmail.com>2015-06-03 21:18:55 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2015-06-04 00:09:05 +0200
commitaa33db32380fe05a3bc7a2e320bbf63a6adddf08 (patch)
tree6794c5f2c1a46e1e319f50860bf4b7d558b24587 /deps/uv/src/unix
parenta804026c9b5b9f8d6316fd5e9fdb9f96f7e1c6b3 (diff)
downloadandroid-node-v8-aa33db32380fe05a3bc7a2e320bbf63a6adddf08.tar.gz
android-node-v8-aa33db32380fe05a3bc7a2e320bbf63a6adddf08.tar.bz2
android-node-v8-aa33db32380fe05a3bc7a2e320bbf63a6adddf08.zip
deps: update libuv to version 1.6.0
Fixes: https://github.com/joyent/node/issues/9310 PR-URL: https://github.com/nodejs/io.js/pull/1889 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'deps/uv/src/unix')
-rw-r--r--deps/uv/src/unix/aix.c63
-rw-r--r--deps/uv/src/unix/android-ifaddrs.c20
-rw-r--r--deps/uv/src/unix/core.c97
-rw-r--r--deps/uv/src/unix/darwin.c16
-rw-r--r--deps/uv/src/unix/dl.c6
-rw-r--r--deps/uv/src/unix/freebsd.c36
-rw-r--r--deps/uv/src/unix/fs.c26
-rw-r--r--deps/uv/src/unix/fsevents.c30
-rw-r--r--deps/uv/src/unix/getaddrinfo.c8
-rw-r--r--deps/uv/src/unix/internal.h3
-rw-r--r--deps/uv/src/unix/kqueue.c4
-rw-r--r--deps/uv/src/unix/linux-core.c49
-rw-r--r--deps/uv/src/unix/linux-inotify.c4
-rw-r--r--deps/uv/src/unix/loop.c2
-rw-r--r--deps/uv/src/unix/netbsd.c30
-rw-r--r--deps/uv/src/unix/openbsd.c30
-rw-r--r--deps/uv/src/unix/pipe.c6
-rw-r--r--deps/uv/src/unix/process.c6
-rw-r--r--deps/uv/src/unix/proctitle.c4
-rw-r--r--deps/uv/src/unix/stream.c37
-rw-r--r--deps/uv/src/unix/sunos.c20
-rw-r--r--deps/uv/src/unix/thread.c6
-rw-r--r--deps/uv/src/unix/udp.c26
23 files changed, 335 insertions, 194 deletions
diff --git a/deps/uv/src/unix/aix.c b/deps/uv/src/unix/aix.c
index e21a9cc78b..a2b0744a04 100644
--- a/deps/uv/src/unix/aix.c
+++ b/deps/uv/src/unix/aix.c
@@ -50,7 +50,9 @@
#include <sys/pollset.h>
#include <ctype.h>
+#ifdef HAVE_SYS_AHAFS_EVPRODS_H
#include <sys/ahafs_evProds.h>
+#endif
#include <sys/mntctl.h>
#include <sys/vmount.h>
@@ -501,6 +503,7 @@ void uv_loadavg(double avg[3]) {
}
+#ifdef HAVE_SYS_AHAFS_EVPRODS_H
static char *uv__rawname(char *cp) {
static char rawbuf[FILENAME_MAX+1];
char *dp = rindex(cp, '/');
@@ -550,7 +553,7 @@ static int uv__is_ahafs_mounted(void){
const char *dev = "/aha";
char *obj, *stub;
- p = malloc(siz);
+ p = uv__malloc(siz);
if (p == NULL)
return -errno;
@@ -561,8 +564,8 @@ static int uv__is_ahafs_mounted(void){
if (rv == 0) {
/* buffer was not large enough, reallocate to correct size */
siz = *(int*)p;
- free(p);
- p = malloc(siz);
+ uv__free(p);
+ p = uv__malloc(siz);
if (p == NULL)
return -errno;
rv = mntctl(MCTL_QUERY, siz, (char*)p);
@@ -576,7 +579,7 @@ static int uv__is_ahafs_mounted(void){
stub = vmt2dataptr(vmt, VMT_STUB); /* mount point */
if (EQ(obj, dev) || EQ(uv__rawname(obj), dev) || EQ(stub, dev)) {
- free(p); /* Found a match */
+ uv__free(p); /* Found a match */
return 0;
}
vmt = (struct vmount *) ((char *) vmt + vmt->vmt_length);
@@ -781,7 +784,7 @@ static int uv__parse_data(char *buf, int *events, uv_fs_event_t* handle) {
/* Scan out the name of the file that triggered the event*/
if (sscanf(p, "BEGIN_EVPROD_INFO\n%sEND_EVPROD_INFO", filename) == 1) {
- handle->dir_filename = strdup((const char*)&filename);
+ handle->dir_filename = uv__strdup((const char*)&filename);
} else
return -1;
}
@@ -859,11 +862,16 @@ static void uv__ahafs_event(uv_loop_t* loop, uv__io_t* event_watch, unsigned int
else /* Call the actual JavaScript callback function */
handle->cb(handle, (const char*)&fname, events, 0);
}
+#endif
int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) {
+#ifdef HAVE_SYS_AHAFS_EVPRODS_H
uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT);
return 0;
+#else
+ return -ENOSYS;
+#endif
}
@@ -871,6 +879,7 @@ int uv_fs_event_start(uv_fs_event_t* handle,
uv_fs_event_cb cb,
const char* filename,
unsigned int flags) {
+#ifdef HAVE_SYS_AHAFS_EVPRODS_H
int fd, rc, i = 0, res = 0;
char cwd[PATH_MAX];
char absolute_path[PATH_MAX];
@@ -931,17 +940,20 @@ int uv_fs_event_start(uv_fs_event_t* handle,
/* Setup/Initialize all the libuv routines */
uv__handle_start(handle);
uv__io_init(&handle->event_watcher, uv__ahafs_event, fd);
- handle->path = strdup((const char*)&absolute_path);
+ handle->path = uv__strdup((const char*)&absolute_path);
handle->cb = cb;
uv__io_start(handle->loop, &handle->event_watcher, UV__POLLIN);
return 0;
+#else
+ return -ENOSYS;
+#endif
}
int uv_fs_event_stop(uv_fs_event_t* handle) {
-
+#ifdef HAVE_SYS_AHAFS_EVPRODS_H
if (!uv__is_active(handle))
return 0;
@@ -949,21 +961,28 @@ int uv_fs_event_stop(uv_fs_event_t* handle) {
uv__handle_stop(handle);
if (uv__path_is_a_directory(handle->path) == 0) {
- free(handle->dir_filename);
+ uv__free(handle->dir_filename);
handle->dir_filename = NULL;
}
- free(handle->path);
+ uv__free(handle->path);
handle->path = NULL;
uv__close(handle->event_watcher.fd);
handle->event_watcher.fd = -1;
return 0;
+#else
+ return -ENOSYS;
+#endif
}
void uv__fs_event_close(uv_fs_event_t* handle) {
+#ifdef HAVE_SYS_AHAFS_EVPRODS_H
uv_fs_event_stop(handle);
+#else
+ UNREACHABLE();
+#endif
}
@@ -1052,7 +1071,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
return -ENOSYS;
}
- ps_cpus = (perfstat_cpu_t*) malloc(ncpus * sizeof(perfstat_cpu_t));
+ ps_cpus = (perfstat_cpu_t*) uv__malloc(ncpus * sizeof(perfstat_cpu_t));
if (!ps_cpus) {
return -ENOMEM;
}
@@ -1060,13 +1079,13 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
strcpy(cpu_id.name, FIRST_CPU);
result = perfstat_cpu(&cpu_id, ps_cpus, sizeof(perfstat_cpu_t), ncpus);
if (result == -1) {
- free(ps_cpus);
+ uv__free(ps_cpus);
return -ENOSYS;
}
- *cpu_infos = (uv_cpu_info_t*) malloc(ncpus * sizeof(uv_cpu_info_t));
+ *cpu_infos = (uv_cpu_info_t*) uv__malloc(ncpus * sizeof(uv_cpu_info_t));
if (!*cpu_infos) {
- free(ps_cpus);
+ uv__free(ps_cpus);
return -ENOMEM;
}
@@ -1075,7 +1094,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
cpu_info = *cpu_infos;
while (idx < ncpus) {
cpu_info->speed = (int)(ps_total.processorHZ / 1000000);
- cpu_info->model = strdup(ps_total.description);
+ cpu_info->model = uv__strdup(ps_total.description);
cpu_info->cpu_times.user = ps_cpus[idx].user;
cpu_info->cpu_times.sys = ps_cpus[idx].sys;
cpu_info->cpu_times.idle = ps_cpus[idx].idle;
@@ -1085,7 +1104,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
idx++;
}
- free(ps_cpus);
+ uv__free(ps_cpus);
return 0;
}
@@ -1094,10 +1113,10 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int i;
for (i = 0; i < count; ++i) {
- free(cpu_infos[i].model);
+ uv__free(cpu_infos[i].model);
}
- free(cpu_infos);
+ uv__free(cpu_infos);
}
@@ -1119,7 +1138,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
return -errno;
}
- ifc.ifc_req = (struct ifreq*)malloc(size);
+ ifc.ifc_req = (struct ifreq*)uv__malloc(size);
ifc.ifc_len = size;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) == -1) {
SAVE_ERRNO(uv__close(sockfd));
@@ -1153,7 +1172,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
/* Alloc the return interface structs */
*addresses = (uv_interface_address_t*)
- malloc(*count * sizeof(uv_interface_address_t));
+ uv__malloc(*count * sizeof(uv_interface_address_t));
if (!(*addresses)) {
uv__close(sockfd);
return -ENOMEM;
@@ -1181,7 +1200,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
/* All conditions above must match count loop */
- address->name = strdup(p->ifr_name);
+ address->name = uv__strdup(p->ifr_name);
if (p->ifr_addr.sa_family == AF_INET6) {
address->address.address6 = *((struct sockaddr_in6*) &p->ifr_addr);
@@ -1208,10 +1227,10 @@ void uv_free_interface_addresses(uv_interface_address_t* addresses,
int i;
for (i = 0; i < count; ++i) {
- free(addresses[i].name);
+ uv__free(addresses[i].name);
}
- free(addresses);
+ uv__free(addresses);
}
void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) {
diff --git a/deps/uv/src/unix/android-ifaddrs.c b/deps/uv/src/unix/android-ifaddrs.c
index a99b0191d5..71f7290b32 100644
--- a/deps/uv/src/unix/android-ifaddrs.c
+++ b/deps/uv/src/unix/android-ifaddrs.c
@@ -137,8 +137,8 @@ static struct nlmsghdr *getNetlinkResponse(int p_socket, int *p_size, int *p_don
{
int l_read;
- free(l_buffer);
- l_buffer = malloc(l_size);
+ uv__free(l_buffer);
+ l_buffer = uv__malloc(l_size);
if (l_buffer == NULL)
{
return NULL;
@@ -148,7 +148,7 @@ static struct nlmsghdr *getNetlinkResponse(int p_socket, int *p_size, int *p_don
*p_size = l_read;
if(l_read == -2)
{
- free(l_buffer);
+ uv__free(l_buffer);
return NULL;
}
if(l_read >= 0)
@@ -170,7 +170,7 @@ static struct nlmsghdr *getNetlinkResponse(int p_socket, int *p_size, int *p_don
if(l_hdr->nlmsg_type == NLMSG_ERROR)
{
- free(l_buffer);
+ uv__free(l_buffer);
return NULL;
}
}
@@ -183,7 +183,7 @@ static struct nlmsghdr *getNetlinkResponse(int p_socket, int *p_size, int *p_don
static NetlinkList *newListItem(struct nlmsghdr *p_data, unsigned int p_size)
{
- NetlinkList *l_item = malloc(sizeof(NetlinkList));
+ NetlinkList *l_item = uv__malloc(sizeof(NetlinkList));
if (l_item == NULL)
{
return NULL;
@@ -202,8 +202,8 @@ static void freeResultList(NetlinkList *p_list)
{
l_cur = p_list;
p_list = p_list->m_next;
- free(l_cur->m_data);
- free(l_cur);
+ uv__free(l_cur->m_data);
+ uv__free(l_cur);
}
}
@@ -349,7 +349,7 @@ static int interpretLink(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList)
}
}
- l_entry = malloc(sizeof(struct ifaddrs) + sizeof(int) + l_nameSize + l_addrSize + l_dataSize);
+ l_entry = uv__malloc(sizeof(struct ifaddrs) + sizeof(int) + l_nameSize + l_addrSize + l_dataSize);
if (l_entry == NULL)
{
return -1;
@@ -478,7 +478,7 @@ static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList,
}
}
- l_entry = malloc(sizeof(struct ifaddrs) + l_nameSize + l_addrSize);
+ l_entry = uv__malloc(sizeof(struct ifaddrs) + l_nameSize + l_addrSize);
if (l_entry == NULL)
{
return -1;
@@ -698,6 +698,6 @@ void freeifaddrs(struct ifaddrs *ifa)
{
l_cur = ifa;
ifa = ifa->ifa_next;
- free(l_cur);
+ uv__free(l_cur);
}
}
diff --git a/deps/uv/src/unix/core.c b/deps/uv/src/unix/core.c
index 6f284ffa7a..cfb7630436 100644
--- a/deps/uv/src/unix/core.c
+++ b/deps/uv/src/unix/core.c
@@ -38,6 +38,7 @@
#include <limits.h> /* INT_MAX, PATH_MAX */
#include <sys/uio.h> /* writev */
#include <sys/resource.h> /* getrusage */
+#include <pwd.h>
#ifdef __linux__
# include <sys/ioctl.h>
@@ -282,6 +283,9 @@ int uv_backend_timeout(const uv_loop_t* loop) {
if (!QUEUE_EMPTY(&loop->idle_handles))
return 0;
+ if (!QUEUE_EMPTY(&loop->pending_queue))
+ return 0;
+
if (loop->closing_handles)
return 0;
@@ -696,16 +700,20 @@ int uv_fileno(const uv_handle_t* handle, uv_os_fd_t* fd) {
static int uv__run_pending(uv_loop_t* loop) {
QUEUE* q;
+ QUEUE pq;
uv__io_t* w;
if (QUEUE_EMPTY(&loop->pending_queue))
return 0;
- while (!QUEUE_EMPTY(&loop->pending_queue)) {
- q = QUEUE_HEAD(&loop->pending_queue);
+ QUEUE_INIT(&pq);
+ q = QUEUE_HEAD(&loop->pending_queue);
+ QUEUE_SPLIT(&loop->pending_queue, q, &pq);
+
+ while (!QUEUE_EMPTY(&pq)) {
+ q = QUEUE_HEAD(&pq);
QUEUE_REMOVE(q);
QUEUE_INIT(q);
-
w = QUEUE_DATA(q, uv__io_t, pending_queue);
w->cb(loop, w, UV__POLLOUT);
}
@@ -745,8 +753,8 @@ static void maybe_resize(uv_loop_t* loop, unsigned int len) {
}
nwatchers = next_power_of_two(len + 2) - 2;
- watchers = realloc(loop->watchers,
- (nwatchers + 2) * sizeof(loop->watchers[0]));
+ watchers = uv__realloc(loop->watchers,
+ (nwatchers + 2) * sizeof(loop->watchers[0]));
if (watchers == NULL)
abort();
@@ -983,3 +991,82 @@ int uv__dup2_cloexec(int oldfd, int newfd) {
return r;
}
}
+
+
+int uv_os_homedir(char* buffer, size_t* size) {
+ struct passwd pw;
+ struct passwd* result;
+ char* buf;
+ uid_t uid;
+ size_t bufsize;
+ size_t len;
+ int r;
+
+ if (buffer == NULL || size == NULL || *size == 0)
+ return -EINVAL;
+
+ /* Check if the HOME environment variable is set first */
+ buf = getenv("HOME");
+
+ if (buf != NULL) {
+ len = strlen(buf);
+
+ if (len >= *size) {
+ *size = len;
+ return -ENOBUFS;
+ }
+
+ memcpy(buffer, buf, len + 1);
+ *size = len;
+
+ return 0;
+ }
+
+ /* HOME is not set, so call getpwuid() */
+ bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
+
+ if (bufsize <= 0)
+ return -EIO;
+
+ uid = getuid();
+ buf = NULL;
+
+ for (;;) {
+ uv__free(buf);
+ buf = uv__malloc(bufsize);
+
+ if (buf == NULL)
+ return -ENOMEM;
+
+ r = getpwuid_r(uid, &pw, buf, bufsize, &result);
+
+ if (r != ERANGE)
+ break;
+
+ bufsize *= 2;
+ }
+
+ if (r != 0) {
+ uv__free(buf);
+ return -r;
+ }
+
+ if (result == NULL) {
+ uv__free(buf);
+ return -ENOENT;
+ }
+
+ len = strlen(pw.pw_dir);
+
+ if (len >= *size) {
+ *size = len;
+ uv__free(buf);
+ return -ENOBUFS;
+ }
+
+ memcpy(buffer, pw.pw_dir, len + 1);
+ *size = len;
+ uv__free(buf);
+
+ return 0;
+}
diff --git a/deps/uv/src/unix/darwin.c b/deps/uv/src/unix/darwin.c
index d276adac2e..718a81e4c1 100644
--- a/deps/uv/src/unix/darwin.c
+++ b/deps/uv/src/unix/darwin.c
@@ -198,7 +198,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
return -EINVAL; /* FIXME(bnoordhuis) Translate error. */
}
- *cpu_infos = malloc(numcpus * sizeof(**cpu_infos));
+ *cpu_infos = uv__malloc(numcpus * sizeof(**cpu_infos));
if (!(*cpu_infos))
return -ENOMEM; /* FIXME(bnoordhuis) Deallocate info? */
@@ -213,7 +213,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
cpu_info->cpu_times.idle = (uint64_t)(info[i].cpu_ticks[2]) * multiplier;
cpu_info->cpu_times.irq = 0;
- cpu_info->model = strdup(model);
+ cpu_info->model = uv__strdup(model);
cpu_info->speed = cpuspeed/1000000;
}
vm_deallocate(mach_task_self(), (vm_address_t)info, msg_type);
@@ -226,10 +226,10 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int i;
for (i = 0; i < count; i++) {
- free(cpu_infos[i].model);
+ uv__free(cpu_infos[i].model);
}
- free(cpu_infos);
+ uv__free(cpu_infos);
}
@@ -255,7 +255,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
(*count)++;
}
- *addresses = malloc(*count * sizeof(**addresses));
+ *addresses = uv__malloc(*count * sizeof(**addresses));
if (!(*addresses))
return -ENOMEM;
@@ -275,7 +275,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
if (ent->ifa_addr->sa_family == AF_LINK)
continue;
- address->name = strdup(ent->ifa_name);
+ address->name = uv__strdup(ent->ifa_name);
if (ent->ifa_addr->sa_family == AF_INET6) {
address->address.address6 = *((struct sockaddr_in6*) ent->ifa_addr);
@@ -324,8 +324,8 @@ void uv_free_interface_addresses(uv_interface_address_t* addresses,
int i;
for (i = 0; i < count; i++) {
- free(addresses[i].name);
+ uv__free(addresses[i].name);
}
- free(addresses);
+ uv__free(addresses);
}
diff --git a/deps/uv/src/unix/dl.c b/deps/uv/src/unix/dl.c
index ad45fc832d..7c6d41c969 100644
--- a/deps/uv/src/unix/dl.c
+++ b/deps/uv/src/unix/dl.c
@@ -40,7 +40,7 @@ int uv_dlopen(const char* filename, uv_lib_t* lib) {
void uv_dlclose(uv_lib_t* lib) {
if (lib->errmsg) {
- free(lib->errmsg);
+ uv__free(lib->errmsg);
lib->errmsg = NULL;
}
@@ -68,12 +68,12 @@ static int uv__dlerror(uv_lib_t* lib) {
const char* errmsg;
if (lib->errmsg)
- free(lib->errmsg);
+ uv__free(lib->errmsg);
errmsg = dlerror();
if (errmsg) {
- lib->errmsg = strdup(errmsg);
+ lib->errmsg = uv__strdup(errmsg);
return -1;
}
else {
diff --git a/deps/uv/src/unix/freebsd.c b/deps/uv/src/unix/freebsd.c
index 2dbb1ec169..44976f7fe2 100644
--- a/deps/uv/src/unix/freebsd.c
+++ b/deps/uv/src/unix/freebsd.c
@@ -151,7 +151,7 @@ void uv_loadavg(double avg[3]) {
char** uv_setup_args(int argc, char** argv) {
- process_title = argc ? strdup(argv[0]) : NULL;
+ process_title = argc ? uv__strdup(argv[0]) : NULL;
return argv;
}
@@ -159,8 +159,8 @@ char** uv_setup_args(int argc, char** argv) {
int uv_set_process_title(const char* title) {
int oid[4];
- if (process_title) free(process_title);
- process_title = strdup(title);
+ if (process_title) uv__free(process_title);
+ process_title = uv__strdup(title);
oid[0] = CTL_KERN;
oid[1] = KERN_PROC;
@@ -271,7 +271,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0))
return -errno;
- *cpu_infos = malloc(numcpus * sizeof(**cpu_infos));
+ *cpu_infos = uv__malloc(numcpus * sizeof(**cpu_infos));
if (!(*cpu_infos))
return -ENOMEM;
@@ -279,7 +279,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
size = sizeof(cpuspeed);
if (sysctlbyname("hw.clockrate", &cpuspeed, &size, NULL, 0)) {
- SAVE_ERRNO(free(*cpu_infos));
+ SAVE_ERRNO(uv__free(*cpu_infos));
return -errno;
}
@@ -288,21 +288,21 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
*/
size = sizeof(maxcpus);
if (sysctlbyname(maxcpus_key, &maxcpus, &size, NULL, 0)) {
- SAVE_ERRNO(free(*cpu_infos));
+ SAVE_ERRNO(uv__free(*cpu_infos));
return -errno;
}
size = maxcpus * CPUSTATES * sizeof(long);
- cp_times = malloc(size);
+ cp_times = uv__malloc(size);
if (cp_times == NULL) {
- free(*cpu_infos);
+ uv__free(*cpu_infos);
return -ENOMEM;
}
if (sysctlbyname(cptimes_key, cp_times, &size, NULL, 0)) {
- SAVE_ERRNO(free(cp_times));
- SAVE_ERRNO(free(*cpu_infos));
+ SAVE_ERRNO(uv__free(cp_times));
+ SAVE_ERRNO(uv__free(*cpu_infos));
return -errno;
}
@@ -315,13 +315,13 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
cpu_info->cpu_times.idle = (uint64_t)(cp_times[CP_IDLE+cur]) * multiplier;
cpu_info->cpu_times.irq = (uint64_t)(cp_times[CP_INTR+cur]) * multiplier;
- cpu_info->model = strdup(model);
+ cpu_info->model = uv__strdup(model);
cpu_info->speed = cpuspeed;
cur+=CPUSTATES;
}
- free(cp_times);
+ uv__free(cp_times);
return 0;
}
@@ -330,10 +330,10 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int i;
for (i = 0; i < count; i++) {
- free(cpu_infos[i].model);
+ uv__free(cpu_infos[i].model);
}
- free(cpu_infos);
+ uv__free(cpu_infos);
}
@@ -359,7 +359,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
(*count)++;
}
- *addresses = malloc(*count * sizeof(**addresses));
+ *addresses = uv__malloc(*count * sizeof(**addresses));
if (!(*addresses))
return -ENOMEM;
@@ -379,7 +379,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
if (ent->ifa_addr->sa_family == AF_LINK)
continue;
- address->name = strdup(ent->ifa_name);
+ address->name = uv__strdup(ent->ifa_name);
if (ent->ifa_addr->sa_family == AF_INET6) {
address->address.address6 = *((struct sockaddr_in6*) ent->ifa_addr);
@@ -428,8 +428,8 @@ void uv_free_interface_addresses(uv_interface_address_t* addresses,
int i;
for (i = 0; i < count; i++) {
- free(addresses[i].name);
+ uv__free(addresses[i].name);
}
- free(addresses);
+ uv__free(addresses);
}
diff --git a/deps/uv/src/unix/fs.c b/deps/uv/src/unix/fs.c
index 7792801e9b..9dab202dd7 100644
--- a/deps/uv/src/unix/fs.c
+++ b/deps/uv/src/unix/fs.c
@@ -73,7 +73,7 @@
#define PATH \
do { \
- (req)->path = strdup(path); \
+ (req)->path = uv__strdup(path); \
if ((req)->path == NULL) \
return -ENOMEM; \
} \
@@ -85,7 +85,7 @@
size_t new_path_len; \
path_len = strlen((path)) + 1; \
new_path_len = strlen((new_path)) + 1; \
- (req)->path = malloc(path_len + new_path_len); \
+ (req)->path = uv__malloc(path_len + new_path_len); \
if ((req)->path == NULL) \
return -ENOMEM; \
(req)->new_path = (req)->path + path_len; \
@@ -310,7 +310,7 @@ static ssize_t uv__fs_read(uv_fs_t* req) {
done:
if (req->bufs != req->bufsml)
- free(req->bufs);
+ uv__free(req->bufs);
return result;
}
@@ -350,8 +350,8 @@ out:
int i;
for (i = 0; i < n; i++)
- free(dents[i]);
- free(dents);
+ uv__free(dents[i]);
+ uv__free(dents);
}
errno = saved_errno;
@@ -375,7 +375,7 @@ static ssize_t uv__fs_readlink(uv_fs_t* req) {
#endif
}
- buf = malloc(len + 1);
+ buf = uv__malloc(len + 1);
if (buf == NULL) {
errno = ENOMEM;
@@ -385,7 +385,7 @@ static ssize_t uv__fs_readlink(uv_fs_t* req) {
len = readlink(req->path, buf, len);
if (len == -1) {
- free(buf);
+ uv__free(buf);
return -1;
}
@@ -671,7 +671,7 @@ done:
#endif
if (req->bufs != req->bufsml)
- free(req->bufs);
+ uv__free(req->bufs);
return r;
}
@@ -1008,7 +1008,7 @@ int uv_fs_mkdtemp(uv_loop_t* loop,
const char* tpl,
uv_fs_cb cb) {
INIT(MKDTEMP);
- req->path = strdup(tpl);
+ req->path = uv__strdup(tpl);
if (req->path == NULL)
return -ENOMEM;
POST;
@@ -1041,7 +1041,7 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req,
req->nbufs = nbufs;
req->bufs = req->bufsml;
if (nbufs > ARRAY_SIZE(req->bufsml))
- req->bufs = malloc(nbufs * sizeof(*bufs));
+ req->bufs = uv__malloc(nbufs * sizeof(*bufs));
if (req->bufs == NULL)
return -ENOMEM;
@@ -1163,7 +1163,7 @@ int uv_fs_write(uv_loop_t* loop,
req->nbufs = nbufs;
req->bufs = req->bufsml;
if (nbufs > ARRAY_SIZE(req->bufsml))
- req->bufs = malloc(nbufs * sizeof(*bufs));
+ req->bufs = uv__malloc(nbufs * sizeof(*bufs));
if (req->bufs == NULL)
return -ENOMEM;
@@ -1176,7 +1176,7 @@ int uv_fs_write(uv_loop_t* loop,
void uv_fs_req_cleanup(uv_fs_t* req) {
- free((void*) req->path);
+ uv__free((void*)req->path);
req->path = NULL;
req->new_path = NULL;
@@ -1184,6 +1184,6 @@ void uv_fs_req_cleanup(uv_fs_t* req) {
uv__fs_scandir_cleanup(req);
if (req->ptr != &req->statbuf)
- free(req->ptr);
+ uv__free(req->ptr);
req->ptr = NULL;
}
diff --git a/deps/uv/src/unix/fsevents.c b/deps/uv/src/unix/fsevents.c
index 49085306b9..8143f7c1f0 100644
--- a/deps/uv/src/unix/fsevents.c
+++ b/deps/uv/src/unix/fsevents.c
@@ -169,7 +169,7 @@ static void (*pFSEventStreamStop)(FSEventStreamRef);
if (!uv__is_closing((handle)) && uv__is_active((handle))) \
block \
/* Free allocated data */ \
- free(event); \
+ uv__free(event); \
} \
if (err != 0 && !uv__is_closing((handle)) && uv__is_active((handle))) \
(handle)->cb((handle), NULL, 0, err); \
@@ -280,7 +280,7 @@ static void uv__fsevents_event_cb(ConstFSEventStreamRef streamRef,
len = 0;
#endif /* MAC_OS_X_VERSION_10_7 */
- event = malloc(sizeof(*event) + len);
+ event = uv__malloc(sizeof(*event) + len);
if (event == NULL)
break;
@@ -425,7 +425,7 @@ static void uv__fsevents_reschedule(uv_fs_event_t* handle) {
uv_mutex_lock(&state->fsevent_mutex);
path_count = state->fsevent_handle_count;
if (path_count != 0) {
- paths = malloc(sizeof(*paths) * path_count);
+ paths = uv__malloc(sizeof(*paths) * path_count);
if (paths == NULL) {
uv_mutex_unlock(&state->fsevent_mutex);
goto final;
@@ -465,7 +465,7 @@ final:
if (cf_paths == NULL) {
while (i != 0)
pCFRelease(paths[--i]);
- free(paths);
+ uv__free(paths);
} else {
/* CFArray takes ownership of both strings and original C-array */
pCFRelease(cf_paths);
@@ -584,7 +584,7 @@ static int uv__fsevents_loop_init(uv_loop_t* loop) {
if (err)
return err;
- state = calloc(1, sizeof(*state));
+ state = uv__calloc(1, sizeof(*state));
if (state == NULL)
return -ENOMEM;
@@ -662,7 +662,7 @@ fail_sem_init:
uv_mutex_destroy(&loop->cf_mutex);
fail_mutex_init:
- free(state);
+ uv__free(state);
return err;
}
@@ -688,7 +688,7 @@ void uv__fsevents_loop_delete(uv_loop_t* loop) {
q = QUEUE_HEAD(&loop->cf_signals);
s = QUEUE_DATA(q, uv__cf_loop_signal_t, member);
QUEUE_REMOVE(q);
- free(s);
+ uv__free(s);
}
/* Destroy state */
@@ -696,7 +696,7 @@ void uv__fsevents_loop_delete(uv_loop_t* loop) {
uv_sem_destroy(&state->fsevent_sem);
uv_mutex_destroy(&state->fsevent_mutex);
pCFRelease(state->signal_source);
- free(state);
+ uv__free(state);
loop->cf_state = NULL;
}
@@ -756,7 +756,7 @@ static void uv__cf_loop_cb(void* arg) {
uv__fsevents_reschedule(s->handle);
QUEUE_REMOVE(item);
- free(s);
+ uv__free(s);
}
}
@@ -766,7 +766,7 @@ int uv__cf_loop_signal(uv_loop_t* loop, uv_fs_event_t* handle) {
uv__cf_loop_signal_t* item;
uv__cf_loop_state_t* state;
- item = malloc(sizeof(*item));
+ item = uv__malloc(sizeof(*item));
if (item == NULL)
return -ENOMEM;
@@ -808,7 +808,7 @@ int uv__fsevents_init(uv_fs_event_t* handle) {
* Events will occur in other thread.
* Initialize callback for getting them back into event loop's thread
*/
- handle->cf_cb = malloc(sizeof(*handle->cf_cb));
+ handle->cf_cb = uv__malloc(sizeof(*handle->cf_cb));
if (handle->cf_cb == NULL) {
err = -ENOMEM;
goto fail_cf_cb_malloc;
@@ -843,11 +843,11 @@ fail_loop_signal:
uv_mutex_destroy(&handle->cf_mutex);
fail_cf_mutex_init:
- free(handle->cf_cb);
+ uv__free(handle->cf_cb);
handle->cf_cb = NULL;
fail_cf_cb_malloc:
- free(handle->realpath);
+ uv__free(handle->realpath);
handle->realpath = NULL;
handle->realpath_len = 0;
@@ -880,7 +880,7 @@ int uv__fsevents_close(uv_fs_event_t* handle) {
/* Wait for deinitialization */
uv_sem_wait(&state->fsevent_sem);
- uv_close((uv_handle_t*) handle->cf_cb, (uv_close_cb) free);
+ uv_close((uv_handle_t*) handle->cf_cb, (uv_close_cb) uv__free);
handle->cf_cb = NULL;
/* Free data in queue */
@@ -889,7 +889,7 @@ int uv__fsevents_close(uv_fs_event_t* handle) {
});
uv_mutex_destroy(&handle->cf_mutex);
- free(handle->realpath);
+ uv__free(handle->realpath);
handle->realpath = NULL;
handle->realpath_len = 0;
diff --git a/deps/uv/src/unix/getaddrinfo.c b/deps/uv/src/unix/getaddrinfo.c
index 0d684e24e1..2049aea2f3 100644
--- a/deps/uv/src/unix/getaddrinfo.c
+++ b/deps/uv/src/unix/getaddrinfo.c
@@ -112,11 +112,11 @@ static void uv__getaddrinfo_done(struct uv__work* w, int status) {
/* See initialization in uv_getaddrinfo(). */
if (req->hints)
- free(req->hints);
+ uv__free(req->hints);
else if (req->service)
- free(req->service);
+ uv__free(req->service);
else if (req->hostname)
- free(req->hostname);
+ uv__free(req->hostname);
else
assert(0);
@@ -152,7 +152,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
hostname_len = hostname ? strlen(hostname) + 1 : 0;
service_len = service ? strlen(service) + 1 : 0;
hints_len = hints ? sizeof(*hints) : 0;
- buf = malloc(hostname_len + service_len + hints_len);
+ buf = uv__malloc(hostname_len + service_len + hints_len);
if (buf == NULL)
return -ENOMEM;
diff --git a/deps/uv/src/unix/internal.h b/deps/uv/src/unix/internal.h
index 31db5e29ea..c31e54992d 100644
--- a/deps/uv/src/unix/internal.h
+++ b/deps/uv/src/unix/internal.h
@@ -143,7 +143,8 @@ enum {
UV_TCP_NODELAY = 0x400, /* Disable Nagle. */
UV_TCP_KEEPALIVE = 0x800, /* Turn on keep-alive. */
UV_TCP_SINGLE_ACCEPT = 0x1000, /* Only accept() when idle. */
- UV_HANDLE_IPV6 = 0x10000 /* Handle is bound to a IPv6 socket. */
+ UV_HANDLE_IPV6 = 0x10000, /* Handle is bound to a IPv6 socket. */
+ UV_UDP_PROCESSING = 0x20000 /* Handle is running the send callback queue. */
};
/* loop flags */
diff --git a/deps/uv/src/unix/kqueue.c b/deps/uv/src/unix/kqueue.c
index aaadcd8419..424236a6ef 100644
--- a/deps/uv/src/unix/kqueue.c
+++ b/deps/uv/src/unix/kqueue.c
@@ -363,7 +363,7 @@ int uv_fs_event_start(uv_fs_event_t* handle,
uv__handle_start(handle);
uv__io_init(&handle->event_watcher, uv__fs_event, fd);
- handle->path = strdup(path);
+ handle->path = uv__strdup(path);
handle->cb = cb;
#if defined(__APPLE__)
@@ -403,7 +403,7 @@ int uv_fs_event_stop(uv_fs_event_t* handle) {
uv__io_close(handle->loop, &handle->event_watcher);
}
- free(handle->path);
+ uv__free(handle->path);
handle->path = NULL;
uv__close(handle->event_watcher.fd);
diff --git a/deps/uv/src/unix/linux-core.c b/deps/uv/src/unix/linux-core.c
index d07494dd65..e6e68283d5 100644
--- a/deps/uv/src/unix/linux-core.c
+++ b/deps/uv/src/unix/linux-core.c
@@ -141,17 +141,26 @@ void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) {
void uv__io_poll(uv_loop_t* loop, int timeout) {
+ /* A bug in kernels < 2.6.37 makes timeouts larger than ~30 minutes
+ * effectively infinite on 32 bits architectures. To avoid blocking
+ * indefinitely, we cap the timeout and poll again if necessary.
+ *
+ * Note that "30 minutes" is a simplification because it depends on
+ * the value of CONFIG_HZ. The magic constant assumes CONFIG_HZ=1200,
+ * that being the largest value I have seen in the wild (and only once.)
+ */
+ static const int max_safe_timeout = 1789569;
static int no_epoll_pwait;
static int no_epoll_wait;
struct uv__epoll_event events[1024];
struct uv__epoll_event* pe;
struct uv__epoll_event e;
+ int real_timeout;
QUEUE* q;
uv__io_t* w;
sigset_t sigset;
uint64_t sigmask;
uint64_t base;
- uint64_t diff;
int nevents;
int count;
int nfds;
@@ -209,8 +218,15 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
assert(timeout >= -1);
base = loop->time;
count = 48; /* Benchmarks suggest this gives the best throughput. */
+ real_timeout = timeout;
for (;;) {
+ /* See the comment for max_safe_timeout for an explanation of why
+ * this is necessary. Executive summary: kernel bug workaround.
+ */
+ if (sizeof(int32_t) == sizeof(long) && timeout >= max_safe_timeout)
+ timeout = max_safe_timeout;
+
if (sigmask != 0 && no_epoll_pwait != 0)
if (pthread_sigmask(SIG_BLOCK, &sigset, NULL))
abort();
@@ -244,6 +260,11 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
if (nfds == 0) {
assert(timeout != -1);
+
+ timeout = real_timeout - timeout;
+ if (timeout > 0)
+ continue;
+
return;
}
@@ -346,11 +367,11 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
update_timeout:
assert(timeout > 0);
- diff = loop->time - base;
- if (diff >= (uint64_t) timeout)
+ real_timeout -= (loop->time - base);
+ if (real_timeout <= 0)
return;
- timeout -= diff;
+ timeout = real_timeout;
}
}
@@ -523,7 +544,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
assert(numcpus != (unsigned int) -1);
assert(numcpus != 0);
- ci = calloc(numcpus, sizeof(*ci));
+ ci = uv__calloc(numcpus, sizeof(*ci));
if (ci == NULL)
return -ENOMEM;
@@ -595,7 +616,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
if (model_idx < numcpus) {
if (strncmp(buf, model_marker, sizeof(model_marker) - 1) == 0) {
model = buf + sizeof(model_marker) - 1;
- model = strndup(model, strlen(model) - 1); /* Strip newline. */
+ model = uv__strndup(model, strlen(model) - 1); /* Strip newline. */
if (model == NULL) {
fclose(fp);
return -ENOMEM;
@@ -614,7 +635,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
#endif
if (strncmp(buf, model_marker, sizeof(model_marker) - 1) == 0) {
model = buf + sizeof(model_marker) - 1;
- model = strndup(model, strlen(model) - 1); /* Strip newline. */
+ model = uv__strndup(model, strlen(model) - 1); /* Strip newline. */
if (model == NULL) {
fclose(fp);
return -ENOMEM;
@@ -645,7 +666,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
inferred_model = ci[model_idx - 1].model;
while (model_idx < numcpus) {
- model = strndup(inferred_model, strlen(inferred_model));
+ model = uv__strndup(inferred_model, strlen(inferred_model));
if (model == NULL)
return -ENOMEM;
ci[model_idx++].model = model;
@@ -755,10 +776,10 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int i;
for (i = 0; i < count; i++) {
- free(cpu_infos[i].model);
+ uv__free(cpu_infos[i].model);
}
- free(cpu_infos);
+ uv__free(cpu_infos);
}
@@ -792,7 +813,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
if (*count == 0)
return 0;
- *addresses = malloc(*count * sizeof(**addresses));
+ *addresses = uv__malloc(*count * sizeof(**addresses));
if (!(*addresses))
return -ENOMEM;
@@ -812,7 +833,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
if (ent->ifa_addr->sa_family == PF_PACKET)
continue;
- address->name = strdup(ent->ifa_name);
+ address->name = uv__strdup(ent->ifa_name);
if (ent->ifa_addr->sa_family == AF_INET6) {
address->address.address6 = *((struct sockaddr_in6*) ent->ifa_addr);
@@ -862,10 +883,10 @@ void uv_free_interface_addresses(uv_interface_address_t* addresses,
int i;
for (i = 0; i < count; i++) {
- free(addresses[i].name);
+ uv__free(addresses[i].name);
}
- free(addresses);
+ uv__free(addresses);
}
diff --git a/deps/uv/src/unix/linux-inotify.c b/deps/uv/src/unix/linux-inotify.c
index 2ecc5ebfb6..d9ed9f4b24 100644
--- a/deps/uv/src/unix/linux-inotify.c
+++ b/deps/uv/src/unix/linux-inotify.c
@@ -207,7 +207,7 @@ int uv_fs_event_start(uv_fs_event_t* handle,
if (w)
goto no_insert;
- w = malloc(sizeof(*w) + strlen(path) + 1);
+ w = uv__malloc(sizeof(*w) + strlen(path) + 1);
if (w == NULL)
return -ENOMEM;
@@ -245,7 +245,7 @@ int uv_fs_event_stop(uv_fs_event_t* handle) {
/* No watchers left for this path. Clean up. */
RB_REMOVE(watcher_root, CAST(&handle->loop->inotify_watchers), w);
uv__inotify_rm_watch(handle->loop->inotify_fd, w->wd);
- free(w);
+ uv__free(w);
}
return 0;
diff --git a/deps/uv/src/unix/loop.c b/deps/uv/src/unix/loop.c
index 7e167d049e..aa9146bf9a 100644
--- a/deps/uv/src/unix/loop.c
+++ b/deps/uv/src/unix/loop.c
@@ -117,7 +117,7 @@ void uv__loop_close(uv_loop_t* loop) {
assert(loop->nfds == 0);
#endif
- free(loop->watchers);
+ uv__free(loop->watchers);
loop->watchers = NULL;
loop->nwatchers = 0;
}
diff --git a/deps/uv/src/unix/netbsd.c b/deps/uv/src/unix/netbsd.c
index 9eb0679de9..29f2a4dec6 100644
--- a/deps/uv/src/unix/netbsd.c
+++ b/deps/uv/src/unix/netbsd.c
@@ -131,15 +131,15 @@ uint64_t uv_get_total_memory(void) {
char** uv_setup_args(int argc, char** argv) {
- process_title = argc ? strdup(argv[0]) : NULL;
+ process_title = argc ? uv__strdup(argv[0]) : NULL;
return argv;
}
int uv_set_process_title(const char* title) {
- if (process_title) free(process_title);
+ if (process_title) uv__free(process_title);
- process_title = strdup(title);
+ process_title = uv__strdup(title);
setproctitle("%s", title);
return 0;
@@ -234,17 +234,17 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
cpuspeed = 0;
size = numcpus * CPUSTATES * sizeof(*cp_times);
- cp_times = malloc(size);
+ cp_times = uv__malloc(size);
if (cp_times == NULL)
return -ENOMEM;
if (sysctlbyname("kern.cp_time", cp_times, &size, NULL, 0))
return -errno;
- *cpu_infos = malloc(numcpus * sizeof(**cpu_infos));
+ *cpu_infos = uv__malloc(numcpus * sizeof(**cpu_infos));
if (!(*cpu_infos)) {
- free(cp_times);
- free(*cpu_infos);
+ uv__free(cp_times);
+ uv__free(*cpu_infos);
return -ENOMEM;
}
@@ -255,11 +255,11 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
cpu_info->cpu_times.sys = (uint64_t)(cp_times[CP_SYS+cur]) * multiplier;
cpu_info->cpu_times.idle = (uint64_t)(cp_times[CP_IDLE+cur]) * multiplier;
cpu_info->cpu_times.irq = (uint64_t)(cp_times[CP_INTR+cur]) * multiplier;
- cpu_info->model = strdup(model);
+ cpu_info->model = uv__strdup(model);
cpu_info->speed = (int)(cpuspeed/(uint64_t) 1e6);
cur += CPUSTATES;
}
- free(cp_times);
+ uv__free(cp_times);
return 0;
}
@@ -268,10 +268,10 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int i;
for (i = 0; i < count; i++) {
- free(cpu_infos[i].model);
+ uv__free(cpu_infos[i].model);
}
- free(cpu_infos);
+ uv__free(cpu_infos);
}
@@ -296,7 +296,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
(*count)++;
}
- *addresses = malloc(*count * sizeof(**addresses));
+ *addresses = uv__malloc(*count * sizeof(**addresses));
if (!(*addresses))
return -ENOMEM;
@@ -313,7 +313,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
if (ent->ifa_addr->sa_family != PF_INET)
continue;
- address->name = strdup(ent->ifa_name);
+ address->name = uv__strdup(ent->ifa_name);
if (ent->ifa_addr->sa_family == AF_INET6) {
address->address.address6 = *((struct sockaddr_in6*) ent->ifa_addr);
@@ -361,8 +361,8 @@ void uv_free_interface_addresses(uv_interface_address_t* addresses, int count) {
int i;
for (i = 0; i < count; i++) {
- free(addresses[i].name);
+ uv__free(addresses[i].name);
}
- free(addresses);
+ uv__free(addresses);
}
diff --git a/deps/uv/src/unix/openbsd.c b/deps/uv/src/unix/openbsd.c
index 859bc0ccb1..c8d5459938 100644
--- a/deps/uv/src/unix/openbsd.c
+++ b/deps/uv/src/unix/openbsd.c
@@ -91,7 +91,7 @@ int uv_exepath(char* buffer, size_t* size) {
mypid = getpid();
for (;;) {
err = -ENOMEM;
- argsbuf_tmp = realloc(argsbuf, argsbuf_size);
+ argsbuf_tmp = uv__realloc(argsbuf, argsbuf_size);
if (argsbuf_tmp == NULL)
goto out;
argsbuf = argsbuf_tmp;
@@ -124,7 +124,7 @@ int uv_exepath(char* buffer, size_t* size) {
err = 0;
out:
- free(argsbuf);
+ uv__free(argsbuf);
return err;
}
@@ -155,14 +155,14 @@ uint64_t uv_get_total_memory(void) {
char** uv_setup_args(int argc, char** argv) {
- process_title = argc ? strdup(argv[0]) : NULL;
+ process_title = argc ? uv__strdup(argv[0]) : NULL;
return argv;
}
int uv_set_process_title(const char* title) {
- if (process_title) free(process_title);
- process_title = strdup(title);
+ if (process_title) uv__free(process_title);
+ process_title = uv__strdup(title);
setproctitle(title);
return 0;
}
@@ -238,7 +238,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
if (sysctl(which, 2, &numcpus, &size, NULL, 0))
return -errno;
- *cpu_infos = malloc(numcpus * sizeof(**cpu_infos));
+ *cpu_infos = uv__malloc(numcpus * sizeof(**cpu_infos));
if (!(*cpu_infos))
return -ENOMEM;
@@ -247,7 +247,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
which[1] = HW_CPUSPEED;
size = sizeof(cpuspeed);
if (sysctl(which, 2, &cpuspeed, &size, NULL, 0)) {
- SAVE_ERRNO(free(*cpu_infos));
+ SAVE_ERRNO(uv__free(*cpu_infos));
return -errno;
}
@@ -258,7 +258,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
which[2] = i;
size = sizeof(info);
if (sysctl(which, 3, &info, &size, NULL, 0)) {
- SAVE_ERRNO(free(*cpu_infos));
+ SAVE_ERRNO(uv__free(*cpu_infos));
return -errno;
}
@@ -270,7 +270,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
cpu_info->cpu_times.idle = (uint64_t)(info[CP_IDLE]) * multiplier;
cpu_info->cpu_times.irq = (uint64_t)(info[CP_INTR]) * multiplier;
- cpu_info->model = strdup(model);
+ cpu_info->model = uv__strdup(model);
cpu_info->speed = cpuspeed;
}
@@ -282,10 +282,10 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int i;
for (i = 0; i < count; i++) {
- free(cpu_infos[i].model);
+ uv__free(cpu_infos[i].model);
}
- free(cpu_infos);
+ uv__free(cpu_infos);
}
@@ -311,7 +311,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
(*count)++;
}
- *addresses = malloc(*count * sizeof(**addresses));
+ *addresses = uv__malloc(*count * sizeof(**addresses));
if (!(*addresses))
return -ENOMEM;
@@ -328,7 +328,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
if (ent->ifa_addr->sa_family != PF_INET)
continue;
- address->name = strdup(ent->ifa_name);
+ address->name = uv__strdup(ent->ifa_name);
if (ent->ifa_addr->sa_family == AF_INET6) {
address->address.address6 = *((struct sockaddr_in6*) ent->ifa_addr);
@@ -377,8 +377,8 @@ void uv_free_interface_addresses(uv_interface_address_t* addresses,
int i;
for (i = 0; i < count; i++) {
- free(addresses[i].name);
+ uv__free(addresses[i].name);
}
- free(addresses);
+ uv__free(addresses);
}
diff --git a/deps/uv/src/unix/pipe.c b/deps/uv/src/unix/pipe.c
index bc8b856337..7f87a713bf 100644
--- a/deps/uv/src/unix/pipe.c
+++ b/deps/uv/src/unix/pipe.c
@@ -54,7 +54,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
return -EINVAL;
/* Make a copy of the file name, it outlives this function's scope. */
- pipe_fname = strdup(name);
+ pipe_fname = uv__strdup(name);
if (pipe_fname == NULL)
return -ENOMEM;
@@ -88,7 +88,7 @@ err_bind:
uv__close(sockfd);
err_socket:
- free((void*)pipe_fname);
+ uv__free((void*)pipe_fname);
return err;
}
@@ -116,7 +116,7 @@ void uv__pipe_close(uv_pipe_t* handle) {
* another thread or process.
*/
unlink(handle->pipe_fname);
- free((void*)handle->pipe_fname);
+ uv__free((void*)handle->pipe_fname);
handle->pipe_fname = NULL;
}
diff --git a/deps/uv/src/unix/process.c b/deps/uv/src/unix/process.c
index 380f3db1dc..f2a83753ee 100644
--- a/deps/uv/src/unix/process.c
+++ b/deps/uv/src/unix/process.c
@@ -404,7 +404,7 @@ int uv_spawn(uv_loop_t* loop,
stdio_count = 3;
err = -ENOMEM;
- pipes = malloc(stdio_count * sizeof(*pipes));
+ pipes = uv__malloc(stdio_count * sizeof(*pipes));
if (pipes == NULL)
goto error;
@@ -509,7 +509,7 @@ int uv_spawn(uv_loop_t* loop,
process->pid = pid;
process->exit_cb = options->exit_cb;
- free(pipes);
+ uv__free(pipes);
return exec_errorno;
error:
@@ -523,7 +523,7 @@ error:
if (pipes[i][1] != -1)
close(pipes[i][1]);
}
- free(pipes);
+ uv__free(pipes);
}
return err;
diff --git a/deps/uv/src/unix/proctitle.c b/deps/uv/src/unix/proctitle.c
index 16b0523731..19214e5ec9 100644
--- a/deps/uv/src/unix/proctitle.c
+++ b/deps/uv/src/unix/proctitle.c
@@ -55,7 +55,7 @@ char** uv_setup_args(int argc, char** argv) {
/* Add space for the argv pointers. */
size += (argc + 1) * sizeof(char*);
- new_argv = malloc(size);
+ new_argv = uv__malloc(size);
if (new_argv == NULL)
return argv;
args_mem = new_argv;
@@ -97,6 +97,6 @@ int uv_get_process_title(char* buffer, size_t size) {
UV_DESTRUCTOR(static void free_args_mem(void)) {
- free(args_mem); /* Keep valgrind happy. */
+ uv__free(args_mem); /* Keep valgrind happy. */
args_mem = NULL;
}
diff --git a/deps/uv/src/unix/stream.c b/deps/uv/src/unix/stream.c
index 48827b65d3..7ad1658cf8 100644
--- a/deps/uv/src/unix/stream.c
+++ b/deps/uv/src/unix/stream.c
@@ -231,7 +231,6 @@ static void uv__stream_osx_select_cb(uv_async_t* handle) {
/* Get and reset stream's events */
events = s->events;
ACCESS_ONCE(int, s->events) = 0;
- uv_sem_post(&s->async_sem);
assert(events != 0);
assert(events == (events & (UV__POLLIN | UV__POLLOUT)));
@@ -242,6 +241,14 @@ static void uv__stream_osx_select_cb(uv_async_t* handle) {
if ((events & UV__POLLOUT) && uv__io_active(&stream->io_watcher, UV__POLLOUT))
uv__stream_io(stream->loop, &stream->io_watcher, UV__POLLOUT);
+
+ if (stream->flags & UV_CLOSING)
+ return;
+
+ /* NOTE: It is important to do it here, otherwise `select()` might be called
+ * before the actual `uv__read()`, leading to the blocking syscall
+ */
+ uv_sem_post(&s->async_sem);
}
@@ -249,7 +256,7 @@ static void uv__stream_osx_cb_close(uv_handle_t* async) {
uv__stream_select_t* s;
s = container_of(async, uv__stream_select_t, async);
- free(s);
+ uv__free(s);
}
@@ -309,7 +316,7 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) {
sread_sz = ROUND_UP(max_fd + 1, sizeof(uint32_t) * NBBY) / NBBY;
swrite_sz = sread_sz;
- s = malloc(sizeof(*s) + sread_sz + swrite_sz);
+ s = uv__malloc(sizeof(*s) + sread_sz + swrite_sz);
if (s == NULL) {
err = -ENOMEM;
goto failed_malloc;
@@ -368,7 +375,7 @@ failed_close_sem_init:
return err;
failed_async_init:
- free(s);
+ uv__free(s);
failed_malloc:
uv__close(fds[0]);
@@ -605,7 +612,7 @@ done:
/* All read, free */
assert(queued_fds->offset > 0);
if (--queued_fds->offset == 0) {
- free(queued_fds);
+ uv__free(queued_fds);
server->queued_fds = NULL;
} else {
/* Shift rest */
@@ -703,7 +710,7 @@ static void uv__write_req_finish(uv_write_t* req) {
*/
if (req->error == 0) {
if (req->bufs != req->bufsml)
- free(req->bufs);
+ uv__free(req->bufs);
req->bufs = NULL;
}
@@ -914,7 +921,7 @@ static void uv__write_callbacks(uv_stream_t* stream) {
if (req->bufs != NULL) {
stream->write_queue_size -= uv__write_req_size(req);
if (req->bufs != req->bufsml)
- free(req->bufs);
+ uv__free(req->bufs);
req->bufs = NULL;
}
@@ -979,8 +986,8 @@ static int uv__stream_queue_fd(uv_stream_t* stream, int fd) {
queued_fds = stream->queued_fds;
if (queued_fds == NULL) {
queue_size = 8;
- queued_fds = malloc((queue_size - 1) * sizeof(*queued_fds->fds) +
- sizeof(*queued_fds));
+ queued_fds = uv__malloc((queue_size - 1) * sizeof(*queued_fds->fds) +
+ sizeof(*queued_fds));
if (queued_fds == NULL)
return -ENOMEM;
queued_fds->size = queue_size;
@@ -990,9 +997,9 @@ static int uv__stream_queue_fd(uv_stream_t* stream, int fd) {
/* Grow */
} else if (queued_fds->size == queued_fds->offset) {
queue_size = queued_fds->size + 8;
- queued_fds = realloc(queued_fds,
- (queue_size - 1) * sizeof(*queued_fds->fds) +
- sizeof(*queued_fds));
+ queued_fds = uv__realloc(queued_fds,
+ (queue_size - 1) * sizeof(*queued_fds->fds) +
+ sizeof(*queued_fds));
/*
* Allocation failure, report back.
@@ -1357,7 +1364,7 @@ int uv_write2(uv_write_t* req,
req->bufs = req->bufsml;
if (nbufs > ARRAY_SIZE(req->bufsml))
- req->bufs = malloc(nbufs * sizeof(bufs[0]));
+ req->bufs = uv__malloc(nbufs * sizeof(bufs[0]));
if (req->bufs == NULL)
return -ENOMEM;
@@ -1445,7 +1452,7 @@ int uv_try_write(uv_stream_t* stream,
QUEUE_REMOVE(&req.queue);
uv__req_unregister(stream->loop, &req);
if (req.bufs != req.bufsml)
- free(req.bufs);
+ uv__free(req.bufs);
req.bufs = NULL;
/* Do not poll for writable, if we wasn't before calling this */
@@ -1582,7 +1589,7 @@ void uv__stream_close(uv_stream_t* handle) {
queued_fds = handle->queued_fds;
for (i = 0; i < queued_fds->offset; i++)
uv__close(queued_fds->fds[i]);
- free(handle->queued_fds);
+ uv__free(handle->queued_fds);
handle->queued_fds = NULL;
}
diff --git a/deps/uv/src/unix/sunos.c b/deps/uv/src/unix/sunos.c
index c41d0f0e52..05b7a11403 100644
--- a/deps/uv/src/unix/sunos.c
+++ b/deps/uv/src/unix/sunos.c
@@ -433,7 +433,7 @@ int uv_fs_event_start(uv_fs_event_t* handle,
}
uv__handle_start(handle);
- handle->path = strdup(path);
+ handle->path = uv__strdup(path);
handle->fd = PORT_UNUSED;
handle->cb = cb;
@@ -463,7 +463,7 @@ int uv_fs_event_stop(uv_fs_event_t* handle) {
}
handle->fd = PORT_DELETED;
- free(handle->path);
+ uv__free(handle->path);
handle->path = NULL;
handle->fo.fo_name = NULL;
uv__handle_stop(handle);
@@ -582,7 +582,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
lookup_instance++;
}
- *cpu_infos = malloc(lookup_instance * sizeof(**cpu_infos));
+ *cpu_infos = uv__malloc(lookup_instance * sizeof(**cpu_infos));
if (!(*cpu_infos)) {
kstat_close(kc);
return -ENOMEM;
@@ -605,7 +605,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
knp = kstat_data_lookup(ksp, (char*) "brand");
assert(knp->data_type == KSTAT_DATA_STRING);
- cpu_info->model = strdup(KSTAT_NAMED_STR_PTR(knp));
+ cpu_info->model = uv__strdup(KSTAT_NAMED_STR_PTR(knp));
}
lookup_instance++;
@@ -659,10 +659,10 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int i;
for (i = 0; i < count; i++) {
- free(cpu_infos[i].model);
+ uv__free(cpu_infos[i].model);
}
- free(cpu_infos);
+ uv__free(cpu_infos);
}
@@ -692,7 +692,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
(*count)++;
}
- *addresses = malloc(*count * sizeof(**addresses));
+ *addresses = uv__malloc(*count * sizeof(**addresses));
if (!(*addresses))
return -ENOMEM;
@@ -705,7 +705,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
if (ent->ifa_addr == NULL)
continue;
- address->name = strdup(ent->ifa_name);
+ address->name = uv__strdup(ent->ifa_name);
if (ent->ifa_addr->sa_family == AF_INET6) {
address->address.address6 = *((struct sockaddr_in6*) ent->ifa_addr);
@@ -756,8 +756,8 @@ void uv_free_interface_addresses(uv_interface_address_t* addresses,
int i;
for (i = 0; i < count; i++) {
- free(addresses[i].name);
+ uv__free(addresses[i].name);
}
- free(addresses);
+ uv__free(addresses);
}
diff --git a/deps/uv/src/unix/thread.c b/deps/uv/src/unix/thread.c
index ea8563fecf..6080cf5f73 100644
--- a/deps/uv/src/unix/thread.c
+++ b/deps/uv/src/unix/thread.c
@@ -45,7 +45,7 @@ static void* uv__thread_start(void *arg)
ctx_p = arg;
ctx = *ctx_p;
- free(ctx_p);
+ uv__free(ctx_p);
ctx.entry(ctx.arg);
return 0;
@@ -56,7 +56,7 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) {
struct thread_ctx* ctx;
int err;
- ctx = malloc(sizeof(*ctx));
+ ctx = uv__malloc(sizeof(*ctx));
if (ctx == NULL)
return UV_ENOMEM;
@@ -66,7 +66,7 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) {
err = pthread_create(tid, NULL, uv__thread_start, ctx);
if (err)
- free(ctx);
+ uv__free(ctx);
return -err;
}
diff --git a/deps/uv/src/unix/udp.c b/deps/uv/src/unix/udp.c
index 22c2e1388e..f85ab1473a 100644
--- a/deps/uv/src/unix/udp.c
+++ b/deps/uv/src/unix/udp.c
@@ -89,6 +89,9 @@ static void uv__udp_run_completed(uv_udp_t* handle) {
uv_udp_send_t* req;
QUEUE* q;
+ assert(!(handle->flags & UV_UDP_PROCESSING));
+ handle->flags |= UV_UDP_PROCESSING;
+
while (!QUEUE_EMPTY(&handle->write_completed_queue)) {
q = QUEUE_HEAD(&handle->write_completed_queue);
QUEUE_REMOVE(q);
@@ -100,7 +103,7 @@ static void uv__udp_run_completed(uv_udp_t* handle) {
handle->send_queue_count--;
if (req->bufs != req->bufsml)
- free(req->bufs);
+ uv__free(req->bufs);
req->bufs = NULL;
if (req->send_cb == NULL)
@@ -121,6 +124,8 @@ static void uv__udp_run_completed(uv_udp_t* handle) {
if (!uv__io_active(&handle->io_watcher, UV__POLLIN))
uv__handle_stop(handle);
}
+
+ handle->flags &= ~UV_UDP_PROCESSING;
}
@@ -399,7 +404,7 @@ int uv__udp_send(uv_udp_send_t* req,
req->bufs = req->bufsml;
if (nbufs > ARRAY_SIZE(req->bufsml))
- req->bufs = malloc(nbufs * sizeof(bufs[0]));
+ req->bufs = uv__malloc(nbufs * sizeof(bufs[0]));
if (req->bufs == NULL)
return -ENOMEM;
@@ -410,10 +415,11 @@ int uv__udp_send(uv_udp_send_t* req,
QUEUE_INSERT_TAIL(&handle->write_queue, &req->queue);
uv__handle_start(handle);
- if (empty_queue)
+ if (empty_queue && !(handle->flags & UV_UDP_PROCESSING)) {
uv__udp_sendmsg(handle);
- else
+ } else {
uv__io_start(handle->loop, &handle->io_watcher, UV__POLLOUT);
+ }
return 0;
}
@@ -666,13 +672,13 @@ int uv_udp_set_ttl(uv_udp_t* handle, int ttl) {
* so hardcode the size of these options on this platform,
* and use the general uv__setsockopt_maybe_char call on other platforms.
*/
-#if defined(__sun)
+#if defined(__sun) || defined(_AIX)
return uv__setsockopt(handle,
IP_TTL,
IPV6_UNICAST_HOPS,
&ttl,
sizeof(ttl));
-#endif /* defined(__sun) */
+#endif /* defined(__sun) || defined(_AIX) */
return uv__setsockopt_maybe_char(handle,
IP_TTL,
@@ -688,14 +694,14 @@ int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl) {
* IP_MULTICAST_TTL, so hardcode the size of the option in the IPv6 case,
* and use the general uv__setsockopt_maybe_char call otherwise.
*/
-#if defined(__sun)
+#if defined(__sun) || defined(_AIX)
if (handle->flags & UV_HANDLE_IPV6)
return uv__setsockopt(handle,
IP_MULTICAST_TTL,
IPV6_MULTICAST_HOPS,
&ttl,
sizeof(ttl));
-#endif /* defined(__sun) */
+#endif /* defined(__sun) || defined(_AIX) */
return uv__setsockopt_maybe_char(handle,
IP_MULTICAST_TTL,
@@ -711,14 +717,14 @@ int uv_udp_set_multicast_loop(uv_udp_t* handle, int on) {
* IP_MULTICAST_LOOP, so hardcode the size of the option in the IPv6 case,
* and use the general uv__setsockopt_maybe_char call otherwise.
*/
-#if defined(__sun)
+#if defined(__sun) || defined(_AIX)
if (handle->flags & UV_HANDLE_IPV6)
return uv__setsockopt(handle,
IP_MULTICAST_LOOP,
IPV6_MULTICAST_LOOP,
&on,
sizeof(on));
-#endif /* defined(__sun) */
+#endif /* defined(__sun) || defined(_AIX) */
return uv__setsockopt_maybe_char(handle,
IP_MULTICAST_LOOP,