mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-29 18:37:41 +08:00
add memory using debug info.
This commit is contained in:
parent
e774daeab4
commit
72a5287da5
@ -128,13 +128,13 @@ static char empty_string[] = "";
|
||||
|
||||
/* #define DEBUG_MEM */
|
||||
#ifdef DEBUG_MEM
|
||||
static __thread int __nmalloc = 0;
|
||||
static __thread int __ncalloc = 0;
|
||||
static __thread int __nrealloc = 0;
|
||||
static __thread int __nfree = 0;
|
||||
static __thread int __nstrdup = 0;
|
||||
static __thread int __nstrndup = 0;
|
||||
static __thread int __nmemdup = 0;
|
||||
static __thread unsigned long long __nmalloc = 0;
|
||||
static __thread unsigned long long __ncalloc = 0;
|
||||
static __thread unsigned long long __nrealloc = 0;
|
||||
static __thread unsigned long long __nfree = 0;
|
||||
static __thread unsigned long long __nstrdup = 0;
|
||||
static __thread unsigned long long __nstrndup = 0;
|
||||
static __thread unsigned long long __nmemdup = 0;
|
||||
static __thread ssize_t __nsize = 0;
|
||||
#endif
|
||||
|
||||
@ -160,10 +160,10 @@ void acl_default_memstat(const char *filename, int line,
|
||||
void acl_default_meminfo(void)
|
||||
{
|
||||
#ifdef DEBUG_MEM
|
||||
printf("%s(%d): __nmalloc: %d, __ncalloc: %d, __nrealloc: %d, "
|
||||
"__nfree: %d, diff: %d, __nsize: %ld\r\n",
|
||||
printf("%s(%d): __nmalloc: %llu, __ncalloc: %llu, __nrealloc: %llu, "
|
||||
"__nfree: %llu, diff: %llu, __nsize: %lu\r\n",
|
||||
__FUNCTION__, __LINE__, __nmalloc, __ncalloc, __nrealloc,
|
||||
__nfree, __nmalloc + __nrealloc - __nfree,
|
||||
__nfree, __nmalloc - __nfree,
|
||||
(unsigned long) __nsize);
|
||||
#endif
|
||||
}
|
||||
@ -217,6 +217,7 @@ void *acl_default_malloc(const char *filename, int line, size_t len)
|
||||
#ifdef DEBUG_MEM
|
||||
__nmalloc++;
|
||||
__nsize += len;
|
||||
//printf("malloc: %llu, filename=%s, line=%d\r\n", __nmalloc, filename, line);
|
||||
#endif
|
||||
|
||||
#ifdef _USE_GLIB
|
||||
@ -246,6 +247,7 @@ void *acl_default_calloc(const char *filename, int line,
|
||||
|
||||
#ifdef DEBUG_MEM
|
||||
__ncalloc++;
|
||||
//printf("calloc: %llu, file=%s, line=%d\r\n", __ncalloc, filename, line);
|
||||
#endif
|
||||
n = (int) (nmemb * size);
|
||||
ptr = acl_default_malloc(filename, line, n);
|
||||
@ -296,7 +298,10 @@ void *acl_default_realloc(const char *filename, int line,
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MEM
|
||||
__nrealloc++;
|
||||
if (ptr)
|
||||
__nrealloc++;
|
||||
else
|
||||
__nmalloc++;
|
||||
__nsize += len;
|
||||
__nsize -= old_len;
|
||||
#endif
|
||||
@ -349,6 +354,7 @@ void acl_default_free(const char *filename, int line, void *ptr)
|
||||
#ifdef DEBUG_MEM
|
||||
__nfree++;
|
||||
__nsize -= len;
|
||||
//printf("free: %llu, filename=%s, line=%d\n", __nfree, filename, line);
|
||||
#endif
|
||||
|
||||
#ifdef _USE_GLIB
|
||||
|
@ -179,6 +179,9 @@ static bool connect_server(IO_CTX* ctx, int id)
|
||||
return false;
|
||||
}
|
||||
|
||||
ACL_VSTREAM *fp = stream->get_vstream();
|
||||
acl_tcp_so_linger(ACL_VSTREAM_SOCK(fp), 1, 0);
|
||||
|
||||
// 创建连接后的回调函数类
|
||||
client_io_callback* callback = new client_io_callback(ctx, stream, id);
|
||||
|
||||
|
@ -23,6 +23,7 @@ CFLAGS = -c -g -W \
|
||||
-Wcast-qual \
|
||||
-DUSE_FAST_TIME \
|
||||
-DUSE_FAST_RING \
|
||||
#-DDEBUG_MEM \
|
||||
#-DUSE_VALGRIND \
|
||||
#-I/usr/local/include
|
||||
#-DUSE_PRINTF_MACRO
|
||||
|
@ -334,6 +334,8 @@ FIBER_API int acl_fiber_set_fdlimit(int limit);
|
||||
FIBER_API int acl_fiber_gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||
#endif
|
||||
|
||||
FIBER_API void acl_fiber_memstat(void);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -45,7 +45,7 @@ ACL_CHANNEL* acl_channel_create(int elemsize, int bufsize)
|
||||
{
|
||||
ACL_CHANNEL *c;
|
||||
|
||||
c = (ACL_CHANNEL *) calloc(1, sizeof(*c) + bufsize * elemsize);
|
||||
c = (ACL_CHANNEL *) mem_calloc(1, sizeof(*c) + bufsize * elemsize);
|
||||
c->elemsize = elemsize;
|
||||
c->bufsize = bufsize;
|
||||
c->nbuf = 0;
|
||||
@ -57,13 +57,16 @@ ACL_CHANNEL* acl_channel_create(int elemsize, int bufsize)
|
||||
void acl_channel_free(ACL_CHANNEL *c)
|
||||
{
|
||||
if(c != NULL) {
|
||||
if (c->name)
|
||||
free(c->name);
|
||||
if (c->arecv.a)
|
||||
free(c->arecv.a);
|
||||
if (c->asend.a)
|
||||
free(c->asend.a);
|
||||
free(c);
|
||||
if (c->name) {
|
||||
mem_free(c->name);
|
||||
}
|
||||
if (c->arecv.a) {
|
||||
mem_free(c->arecv.a);
|
||||
}
|
||||
if (c->asend.a) {
|
||||
mem_free(c->asend.a);
|
||||
}
|
||||
mem_free(c);
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,7 +74,7 @@ static void array_add(FIBER_ALT_ARRAY *a, FIBER_ALT *alt)
|
||||
{
|
||||
if (a->n == a->m) {
|
||||
a->m += 16;
|
||||
a->a = (FIBER_ALT**) realloc(a->a, a->m * sizeof(a->a[0]));
|
||||
a->a = (FIBER_ALT**) mem_realloc(a->a, a->m * sizeof(a->a[0]));
|
||||
}
|
||||
|
||||
a->a[a->n++] = alt;
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define __COMMON_INCLUDE_H__
|
||||
|
||||
#include "common/init.h"
|
||||
#include "common/memory.h"
|
||||
#include "common/ring.h"
|
||||
#include "common/msg.h"
|
||||
#include "common/atomic.h"
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "stdafx.h"
|
||||
#include "memory.h"
|
||||
#include "strops.h"
|
||||
#include "argv.h"
|
||||
|
||||
@ -11,7 +12,7 @@ static void argv_extend(ARGV *argvp)
|
||||
int new_len;
|
||||
|
||||
new_len = argvp->len * 2;
|
||||
argvp->argv = (char **) realloc((char *) argvp->argv,
|
||||
argvp->argv = (char **) mem_realloc((char *) argvp->argv,
|
||||
(new_len + 1) * sizeof(char *));
|
||||
argvp->len = new_len;
|
||||
}
|
||||
@ -129,10 +130,10 @@ ARGV *argv_free(ARGV *argvp)
|
||||
char **cpp;
|
||||
|
||||
for (cpp = argvp->argv; cpp < argvp->argv + argvp->argc; cpp++) {
|
||||
free(*cpp);
|
||||
mem_free(*cpp);
|
||||
}
|
||||
free(argvp->argv);
|
||||
free(argvp);
|
||||
mem_free(argvp->argv);
|
||||
mem_free(argvp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -145,10 +146,10 @@ ARGV *argv_alloc(int size)
|
||||
|
||||
/* Make sure that always argvp->argc < argvp->len. */
|
||||
|
||||
argvp = (ARGV *) malloc(sizeof(*argvp));
|
||||
argvp = (ARGV *) mem_malloc(sizeof(*argvp));
|
||||
argvp->len = 0;
|
||||
sane_len = (size < 2 ? 2 : size);
|
||||
argvp->argv = (char **) malloc((sane_len + 1) * sizeof(char *));
|
||||
argvp->argv = (char **) mem_malloc((sane_len + 1) * sizeof(char *));
|
||||
argvp->len = sane_len;
|
||||
argvp->argc = 0;
|
||||
argvp->argv[0] = 0;
|
||||
@ -230,6 +231,6 @@ ARGV *argv_split(const char *str, const char *delim)
|
||||
while ((arg = mystrtok(&bp, delim)) != 0)
|
||||
argv_add(argvp, arg, (char *) 0);
|
||||
argv_terminate(argvp);
|
||||
free(saved_string);
|
||||
mem_free(saved_string);
|
||||
return argvp;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "stdafx.h"
|
||||
#include "memory.h"
|
||||
#include "msg.h"
|
||||
#include "array.h"
|
||||
|
||||
@ -125,9 +126,9 @@ static void array_grow(ARRAY *a, int min_capacity)
|
||||
a->capacity += delta;
|
||||
|
||||
if (a->items == NULL) {
|
||||
a->items = (void**) malloc(a->capacity * sizeof(void*));
|
||||
a->items = (void**) mem_malloc(a->capacity * sizeof(void*));
|
||||
} else {
|
||||
a->items = (void**) realloc(a->items, a->capacity * sizeof(void*));
|
||||
a->items = (void**) mem_realloc(a->items, a->capacity * sizeof(void*));
|
||||
}
|
||||
|
||||
/* reset, just in case */
|
||||
@ -139,7 +140,7 @@ ARRAY *array_create(int init_size)
|
||||
{
|
||||
ARRAY *a;
|
||||
|
||||
a = (ARRAY *) calloc(1, sizeof(ARRAY));
|
||||
a = (ARRAY *) mem_calloc(1, sizeof(ARRAY));
|
||||
|
||||
a->push_back = array_push_back;
|
||||
a->push_front = array_push_front;
|
||||
@ -176,9 +177,9 @@ void array_free(ARRAY *a, void (*free_fn)(void *))
|
||||
{
|
||||
array_clean(a, free_fn);
|
||||
if (a->items) {
|
||||
free(a->items);
|
||||
mem_free(a->items);
|
||||
}
|
||||
free(a);
|
||||
mem_free(a);
|
||||
}
|
||||
|
||||
int array_append(ARRAY *a, void *obj)
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "memory.h"
|
||||
#include "msg.h"
|
||||
#include "atomic.h"
|
||||
|
||||
@ -11,7 +12,7 @@ struct ATOMIC {
|
||||
|
||||
ATOMIC *atomic_new(void)
|
||||
{
|
||||
ATOMIC *self = (ATOMIC*) malloc(sizeof(ATOMIC));
|
||||
ATOMIC *self = (ATOMIC*) mem_malloc(sizeof(ATOMIC));
|
||||
|
||||
self->value = NULL;
|
||||
return self;
|
||||
@ -20,7 +21,7 @@ ATOMIC *atomic_new(void)
|
||||
void atomic_free(ATOMIC *self)
|
||||
{
|
||||
self->value = NULL;
|
||||
free(self);
|
||||
mem_free(self);
|
||||
}
|
||||
|
||||
void atomic_set(ATOMIC *self, void *value)
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "stdafx.h"
|
||||
#include "memory.h"
|
||||
#include "iterator.h"
|
||||
#include "fifo.h"
|
||||
|
||||
@ -104,7 +105,7 @@ FIFO *fifo_new(void)
|
||||
{
|
||||
FIFO *fifo;
|
||||
|
||||
fifo = (FIFO *) malloc(sizeof(*fifo));
|
||||
fifo = (FIFO *) mem_malloc(sizeof(*fifo));
|
||||
fifo->head = NULL;
|
||||
fifo->tail = NULL;
|
||||
fifo->cnt = 0;
|
||||
@ -129,14 +130,14 @@ void fifo_free(FIFO *fifo, void (*free_fn)(void *))
|
||||
if (free_fn)
|
||||
free_fn(data);
|
||||
}
|
||||
free(fifo);
|
||||
mem_free(fifo);
|
||||
}
|
||||
|
||||
FIFO_INFO *fifo_push_back(FIFO *fifo, void *data)
|
||||
{
|
||||
FIFO_INFO *info;
|
||||
|
||||
info = (FIFO_INFO *) malloc(sizeof(*info));
|
||||
info = (FIFO_INFO *) mem_malloc(sizeof(*info));
|
||||
info->data = data;
|
||||
|
||||
if (fifo->tail == NULL) {
|
||||
@ -157,7 +158,7 @@ FIFO_INFO *fifo_push_front(FIFO *fifo, void *data)
|
||||
{
|
||||
FIFO_INFO *info;
|
||||
|
||||
info = (FIFO_INFO*) malloc(sizeof(*info));
|
||||
info = (FIFO_INFO*) mem_malloc(sizeof(*info));
|
||||
info->data = data;
|
||||
|
||||
if (fifo->head == NULL) {
|
||||
@ -190,7 +191,7 @@ void *fifo_pop_front(FIFO *fifo)
|
||||
fifo->head = fifo->tail = NULL;
|
||||
}
|
||||
data = info->data;
|
||||
free(info);
|
||||
mem_free(info);
|
||||
fifo->cnt--;
|
||||
return data;
|
||||
}
|
||||
@ -211,7 +212,7 @@ void *fifo_pop_back(FIFO *fifo)
|
||||
fifo->head = fifo->tail = NULL;
|
||||
}
|
||||
data = info->data;
|
||||
free(info);
|
||||
mem_free(info);
|
||||
fifo->cnt--;
|
||||
return data;
|
||||
}
|
||||
@ -230,7 +231,7 @@ int fifo_delete(FIFO *fifo, const void *data)
|
||||
iter->next->prev = iter->prev;
|
||||
else
|
||||
fifo->tail = iter->prev;
|
||||
free(iter);
|
||||
mem_free(iter);
|
||||
fifo->cnt--;
|
||||
return 1;
|
||||
}
|
||||
@ -264,7 +265,7 @@ void fifo_free2(FIFO *fifo, void (*free_fn)(FIFO_INFO *))
|
||||
if (free_fn)
|
||||
free_fn(info);
|
||||
}
|
||||
free(fifo);
|
||||
mem_free(fifo);
|
||||
}
|
||||
|
||||
void fifo_push_info_back(FIFO *fifo, FIFO_INFO *info)
|
||||
@ -312,7 +313,7 @@ void fifo_delete_info(FIFO *fifo, FIFO_INFO *info)
|
||||
else
|
||||
fifo->tail = info->prev;
|
||||
|
||||
free(info);
|
||||
mem_free(info);
|
||||
fifo->cnt--;
|
||||
}
|
||||
|
||||
|
@ -28,14 +28,14 @@ static void dummy(void *ptr fiber_unused)
|
||||
|
||||
static void free_tls(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
mem_free(ptr);
|
||||
}
|
||||
|
||||
static void *__tls = NULL;
|
||||
static void main_free_tls(void)
|
||||
{
|
||||
if (__tls) {
|
||||
free(__tls);
|
||||
mem_free(__tls);
|
||||
__tls = NULL;
|
||||
}
|
||||
}
|
||||
@ -59,7 +59,7 @@ static void *tls_calloc(size_t len)
|
||||
(void) pthread_once(&once_control, once_init);
|
||||
ptr = (void*) pthread_getspecific(once_key);
|
||||
if (ptr == NULL) {
|
||||
ptr = calloc(1, len);
|
||||
ptr = mem_calloc(1, len);
|
||||
pthread_setspecific(once_key, ptr);
|
||||
if (__pthread_self() == main_thread_self()) {
|
||||
__tls = ptr;
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "stdafx.h"
|
||||
#include "memory.h"
|
||||
#include "msg.h"
|
||||
#include "htable.h"
|
||||
|
||||
@ -175,7 +176,7 @@ static int __htable_size(HTABLE *table, unsigned size)
|
||||
|
||||
size |= 1;
|
||||
|
||||
table->data = h = (HTABLE_INFO **) malloc(size * sizeof(HTABLE_INFO *));
|
||||
table->data = h = (HTABLE_INFO **) mem_malloc(size * sizeof(HTABLE_INFO *));
|
||||
if(table->data == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@ -215,7 +216,7 @@ static int htable_grow(HTABLE *table)
|
||||
}
|
||||
}
|
||||
|
||||
free(old_entries);
|
||||
mem_free(old_entries);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -224,7 +225,7 @@ HTABLE *htable_create(int size)
|
||||
HTABLE *table;
|
||||
int ret;
|
||||
|
||||
table = (HTABLE *) calloc(1, sizeof(HTABLE));
|
||||
table = (HTABLE *) mem_calloc(1, sizeof(HTABLE));
|
||||
if (table == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@ -232,7 +233,7 @@ HTABLE *htable_create(int size)
|
||||
table->init_size = size;
|
||||
ret = __htable_size(table, size < 13 ? 13 : size);
|
||||
if(ret < 0) {
|
||||
free(table);
|
||||
mem_free(table);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -291,7 +292,7 @@ HTABLE_INFO *htable_enter(HTABLE *table, const char *key, void *value)
|
||||
}
|
||||
}
|
||||
|
||||
ht = (HTABLE_INFO *) malloc(sizeof(HTABLE_INFO));
|
||||
ht = (HTABLE_INFO *) mem_malloc(sizeof(HTABLE_INFO));
|
||||
if (ht == NULL) {
|
||||
msg_error("%s(%d): alloc error", __FUNCTION__, __LINE__);
|
||||
return NULL;
|
||||
@ -300,11 +301,11 @@ HTABLE_INFO *htable_enter(HTABLE *table, const char *key, void *value)
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
ht->key = _strdup(key);
|
||||
#else
|
||||
ht->key = strdup(key);
|
||||
ht->key = mem_strdup(key);
|
||||
#endif
|
||||
if (ht->key == NULL) {
|
||||
msg_error("%s(%d): alloc error", __FUNCTION__, __LINE__);
|
||||
free(ht);
|
||||
mem_free(ht);
|
||||
return NULL;
|
||||
}
|
||||
ht->hash = hash;
|
||||
@ -355,10 +356,10 @@ void htable_delete_entry(HTABLE *table, HTABLE_INFO *ht,
|
||||
else
|
||||
*h = ht->next;
|
||||
|
||||
free(ht->key);
|
||||
mem_free(ht->key);
|
||||
if (free_fn && ht->value)
|
||||
(*free_fn) (ht->value);
|
||||
free(ht);
|
||||
mem_free(ht);
|
||||
table->used--;
|
||||
}
|
||||
|
||||
@ -395,16 +396,16 @@ void htable_free(HTABLE *table, void (*free_fn) (void *))
|
||||
while (i-- > 0) {
|
||||
for (ht = *h++; ht; ht = next) {
|
||||
next = ht->next;
|
||||
free(ht->key);
|
||||
mem_free(ht->key);
|
||||
if (free_fn && ht->value)
|
||||
(*free_fn) (ht->value);
|
||||
free(ht);
|
||||
mem_free(ht);
|
||||
}
|
||||
}
|
||||
|
||||
free(table->data);
|
||||
mem_free(table->data);
|
||||
table->data = 0;
|
||||
free(table);
|
||||
mem_free(table);
|
||||
}
|
||||
|
||||
int htable_reset(HTABLE *table, void (*free_fn) (void *))
|
||||
@ -420,14 +421,14 @@ int htable_reset(HTABLE *table, void (*free_fn) (void *))
|
||||
while (i-- > 0) {
|
||||
for (ht = *h++; ht; ht = next) {
|
||||
next = ht->next;
|
||||
free(ht->key);
|
||||
mem_free(ht->key);
|
||||
if (free_fn && ht->value) {
|
||||
(*free_fn) (ht->value);
|
||||
}
|
||||
free(ht);
|
||||
mem_free(ht);
|
||||
}
|
||||
}
|
||||
free(table->data);
|
||||
mem_free(table->data);
|
||||
ret = __htable_size(table, table->init_size < 13 ? 13 : table->init_size);
|
||||
return ret;
|
||||
}
|
||||
@ -482,7 +483,7 @@ HTABLE_INFO **htable_list(const HTABLE *table)
|
||||
int i;
|
||||
|
||||
if (table != 0) {
|
||||
list = (HTABLE_INFO **) malloc(sizeof(*list) * (table->used + 1));
|
||||
list = (HTABLE_INFO **) mem_malloc(sizeof(*list) * (table->used + 1));
|
||||
for (i = 0; i < table->size; i++) {
|
||||
for (member = table->data[i]; member != 0;
|
||||
member = member->next) {
|
||||
@ -490,7 +491,7 @@ HTABLE_INFO **htable_list(const HTABLE *table)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
list = (HTABLE_INFO **) malloc(sizeof(*list));
|
||||
list = (HTABLE_INFO **) mem_malloc(sizeof(*list));
|
||||
}
|
||||
list[count] = 0;
|
||||
return list;
|
||||
|
@ -61,19 +61,19 @@ void stack_free(void *ptr)
|
||||
msg_fatal("%s(%d), %s: mprotect error=%s",
|
||||
__FILE__, __LINE__, __FUNCTION__, last_serror());
|
||||
}
|
||||
free(ptr);
|
||||
mem_free(ptr);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void *stack_alloc(size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
return mem_malloc(size);
|
||||
}
|
||||
|
||||
void stack_free(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
mem_free(ptr);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -87,3 +87,61 @@ void *stack_calloc(size_t size)
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
//#define DEBUG_MEM
|
||||
#ifdef DEBUG_MEM
|
||||
static __thread unsigned long long __nmalloc = 0;
|
||||
static __thread unsigned long long __ncalloc = 0;
|
||||
static __thread unsigned long long __nstrdup = 0;
|
||||
static __thread unsigned long long __nrealloc = 0;
|
||||
static __thread unsigned long long __nfree = 0;
|
||||
#endif
|
||||
|
||||
void *mem_malloc(size_t size)
|
||||
{
|
||||
#ifdef DEBUG_MEM
|
||||
__nmalloc++;
|
||||
#endif
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void mem_free(void *ptr)
|
||||
{
|
||||
#ifdef DEBUG_MEM
|
||||
__nfree++;
|
||||
#endif
|
||||
return free(ptr);
|
||||
}
|
||||
|
||||
void *mem_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
#ifdef DEBUG_MEM
|
||||
__ncalloc++;
|
||||
#endif
|
||||
return calloc(nmemb, size);
|
||||
}
|
||||
|
||||
void *mem_realloc(void *ptr, size_t size)
|
||||
{
|
||||
#ifdef DEBUG_MEM
|
||||
__nrealloc++;
|
||||
#endif
|
||||
return realloc(ptr, size);
|
||||
}
|
||||
|
||||
char *mem_strdup(const char *s)
|
||||
{
|
||||
#ifdef DEBUG_MEM
|
||||
__nstrdup++;
|
||||
#endif
|
||||
return strdup(s);
|
||||
}
|
||||
|
||||
void mem_stat(void)
|
||||
{
|
||||
#ifdef DEBUG_MEM
|
||||
printf("malloc=%llu, calloc=%llu, strdup=%llu, realloc=%llu, "
|
||||
"free=%llu, diff=%llu\r\n", __nmalloc, __ncalloc, __nstrdup,
|
||||
__nrealloc, __nfree, __nmalloc + __ncalloc + __nstrdup - __nfree);
|
||||
#endif
|
||||
}
|
||||
|
@ -5,4 +5,11 @@ void *stack_alloc(size_t size);
|
||||
void *stack_calloc(size_t size);
|
||||
void stack_free(void *ptr);
|
||||
|
||||
void *mem_malloc(size_t size);
|
||||
void mem_free(void *ptr);
|
||||
void *mem_calloc(size_t nmemb, size_t size);
|
||||
void *mem_realloc(void *ptr, size_t size);
|
||||
void mem_stat(void);
|
||||
char *mem_strdup(const char *s);
|
||||
|
||||
#endif
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "fiber/libfiber.h"
|
||||
#include "init.h"
|
||||
#include "pthread_patch.h"
|
||||
#include "memory.h"
|
||||
#include "msg.h"
|
||||
|
||||
#ifndef USE_PRINTF_MACRO
|
||||
@ -185,14 +186,14 @@ static char *__main_buf = NULL;
|
||||
static void thread_free_buf(void *buf)
|
||||
{
|
||||
if (__pthread_self() != main_thread_self()) {
|
||||
free(buf);
|
||||
mem_free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
static void main_free_buf(void)
|
||||
{
|
||||
if (__main_buf) {
|
||||
free(__main_buf);
|
||||
mem_free(__main_buf);
|
||||
}
|
||||
}
|
||||
|
||||
@ -217,7 +218,7 @@ const char *last_serror(void)
|
||||
|
||||
buf = (char*) pthread_getspecific(__errbuf_key);
|
||||
if (buf == NULL) {
|
||||
buf = (char*) malloc(__buf_size);
|
||||
buf = (char*) mem_malloc(__buf_size);
|
||||
if (pthread_setspecific(__errbuf_key, buf) != 0)
|
||||
abort();
|
||||
if (__pthread_self() == main_thread_self()) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
#include "fifo.h"
|
||||
#include "memory.h"
|
||||
#include "msg.h"
|
||||
#include "iterator.h"
|
||||
#include "pthread_patch.h"
|
||||
@ -95,7 +96,7 @@ static FIFO *tls_value_list_get(void)
|
||||
|
||||
static void tls_value_list_on_free(void *ctx)
|
||||
{
|
||||
free(ctx);
|
||||
mem_free(ctx);
|
||||
}
|
||||
|
||||
static void tls_value_list_free(void)
|
||||
@ -210,7 +211,7 @@ int pthread_setspecific(pthread_key_t key, void *value)
|
||||
}
|
||||
|
||||
if (TlsSetValue(key, value)) {
|
||||
TLS_VALUE *tls_value = (TLS_VALUE*) malloc(sizeof(TLS_VALUE));
|
||||
TLS_VALUE *tls_value = (TLS_VALUE*) mem_malloc(sizeof(TLS_VALUE));
|
||||
tls_value->tls_key = &__tls_key_list[key];
|
||||
tls_value->value = value;
|
||||
fifo_push(tls_value_list_ptr, tls_value);
|
||||
@ -252,7 +253,7 @@ int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mattr)
|
||||
if (!mutex->id) {
|
||||
msg_error("%s, %s(%d): CreateMutex error(%s)",
|
||||
__FILE__, myname, __LINE__, last_serror());
|
||||
free(mutex);
|
||||
mem_free(mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1724,7 +1724,7 @@ struct dns_packet *dns_p_make(size_t len, int *error) {
|
||||
struct dns_packet *P;
|
||||
size_t size = dns_p_calcsize(len);
|
||||
|
||||
if (!(P = dns_p_init(malloc(size), size)))
|
||||
if (!(P = dns_p_init(mem_malloc(size), size)))
|
||||
*error = dns_syerr();
|
||||
|
||||
return P;
|
||||
@ -1732,7 +1732,7 @@ struct dns_packet *dns_p_make(size_t len, int *error) {
|
||||
|
||||
|
||||
static void dns_p_free(struct dns_packet *P) {
|
||||
free(P);
|
||||
mem_free(P);
|
||||
} /* dns_p_free() */
|
||||
|
||||
|
||||
@ -1777,7 +1777,7 @@ int dns_p_grow(struct dns_packet **P) {
|
||||
if (size > 65536)
|
||||
return DNS_ENOBUFS;
|
||||
|
||||
if (!(tmp = realloc(*P, dns_p_calcsize(size))))
|
||||
if (!(tmp = mem_realloc(*P, dns_p_calcsize(size))))
|
||||
return dns_syerr();
|
||||
|
||||
tmp->size = size;
|
||||
@ -4265,7 +4265,7 @@ struct dns_hosts *dns_hosts_open(int *error) {
|
||||
static const struct dns_hosts hosts_initializer = { .refcount = 1 };
|
||||
struct dns_hosts *hosts;
|
||||
|
||||
if (!(hosts = malloc(sizeof *hosts)))
|
||||
if (!(hosts = mem_malloc(sizeof *hosts)))
|
||||
goto syerr;
|
||||
|
||||
*hosts = hosts_initializer;
|
||||
@ -4276,7 +4276,7 @@ struct dns_hosts *dns_hosts_open(int *error) {
|
||||
syerr:
|
||||
*error = dns_syerr();
|
||||
|
||||
free(hosts);
|
||||
mem_free(hosts);
|
||||
|
||||
return 0;
|
||||
} /* dns_hosts_open() */
|
||||
@ -4291,10 +4291,10 @@ void dns_hosts_close(struct dns_hosts *hosts) {
|
||||
for (ent = hosts->head; ent; ent = xnt) {
|
||||
xnt = ent->next;
|
||||
|
||||
free(ent);
|
||||
mem_free(ent);
|
||||
}
|
||||
|
||||
free(hosts);
|
||||
mem_free(hosts);
|
||||
|
||||
return;
|
||||
} /* dns_hosts_close() */
|
||||
@ -4447,7 +4447,7 @@ int dns_hosts_insert(struct dns_hosts *hosts, int af, const void *addr, const vo
|
||||
struct dns_hosts_entry *ent;
|
||||
int error;
|
||||
|
||||
if (!(ent = malloc(sizeof *ent)))
|
||||
if (!(ent = mem_malloc(sizeof *ent)))
|
||||
goto syerr;
|
||||
|
||||
dns_d_anchor(ent->host, sizeof ent->host, host, strlen(host));
|
||||
@ -4481,7 +4481,7 @@ int dns_hosts_insert(struct dns_hosts *hosts, int af, const void *addr, const vo
|
||||
syerr:
|
||||
error = dns_syerr();
|
||||
error:
|
||||
free(ent);
|
||||
mem_free(ent);
|
||||
|
||||
return error;
|
||||
} /* dns_hosts_insert() */
|
||||
@ -4569,7 +4569,7 @@ struct dns_resolv_conf *dns_resconf_open(int *error) {
|
||||
struct dns_resolv_conf *resconf;
|
||||
struct sockaddr_in *sin;
|
||||
|
||||
if (!(resconf = malloc(sizeof *resconf)))
|
||||
if (!(resconf = mem_malloc(sizeof *resconf)))
|
||||
goto syerr;
|
||||
|
||||
*resconf = resconf_initializer;
|
||||
@ -4599,7 +4599,7 @@ struct dns_resolv_conf *dns_resconf_open(int *error) {
|
||||
syerr:
|
||||
*error = dns_syerr();
|
||||
|
||||
free(resconf);
|
||||
mem_free(resconf);
|
||||
|
||||
return 0;
|
||||
} /* dns_resconf_open() */
|
||||
@ -4609,7 +4609,7 @@ void dns_resconf_close(struct dns_resolv_conf *resconf) {
|
||||
if (!resconf || 1 != dns_resconf_release(resconf))
|
||||
return /* void */;
|
||||
|
||||
free(resconf);
|
||||
mem_free(resconf);
|
||||
} /* dns_resconf_close() */
|
||||
|
||||
|
||||
@ -5709,7 +5709,7 @@ struct dns_hints *dns_hints_open(struct dns_resolv_conf *resconf, int *error) {
|
||||
|
||||
(void)resconf;
|
||||
|
||||
if (!(H = malloc(sizeof *H)))
|
||||
if (!(H = mem_malloc(sizeof *H)))
|
||||
goto syerr;
|
||||
|
||||
*H = H_initializer;
|
||||
@ -5720,7 +5720,7 @@ struct dns_hints *dns_hints_open(struct dns_resolv_conf *resconf, int *error) {
|
||||
syerr:
|
||||
*error = dns_syerr();
|
||||
|
||||
free(H);
|
||||
mem_free(H);
|
||||
|
||||
return 0;
|
||||
} /* dns_hints_open() */
|
||||
@ -5735,10 +5735,10 @@ void dns_hints_close(struct dns_hints *H) {
|
||||
for (soa = H->head; soa; soa = nxt) {
|
||||
nxt = soa->next;
|
||||
|
||||
free(soa);
|
||||
mem_free(soa);
|
||||
}
|
||||
|
||||
free(H);
|
||||
mem_free(H);
|
||||
|
||||
return /* void */;
|
||||
} /* dns_hints_close() */
|
||||
@ -5871,7 +5871,7 @@ int dns_hints_insert(struct dns_hints *H, const char *zone, const struct sockadd
|
||||
unsigned i;
|
||||
|
||||
if (!(soa = dns_hints_fetch(H, zone))) {
|
||||
if (!(soa = malloc(sizeof *soa)))
|
||||
if (!(soa = mem_malloc(sizeof *soa)))
|
||||
return dns_syerr();
|
||||
*soa = soa_initializer;
|
||||
dns_strlcpy((char *)soa->zone, zone, sizeof soa->zone);
|
||||
@ -6442,7 +6442,7 @@ static int dns_so_closefd(struct dns_socket *so, int *fd) {
|
||||
unsigned olim = DNS_PP_MAX(4, so->olim * 2);
|
||||
void *old;
|
||||
|
||||
if (!(old = realloc(so->old, sizeof so->old[0] * olim)))
|
||||
if (!(old = mem_realloc(so->old, sizeof so->old[0] * olim)))
|
||||
return dns_syerr();
|
||||
|
||||
so->old = old;
|
||||
@ -6471,7 +6471,7 @@ static void dns_so_closefds(struct dns_socket *so, int which) {
|
||||
for (i = 0; i < so->onum; i++)
|
||||
dns_socketclose(&so->old[i], &so->opts);
|
||||
so->onum = 0;
|
||||
free(so->old);
|
||||
mem_free(so->old);
|
||||
so->old = 0;
|
||||
so->olim = 0;
|
||||
}
|
||||
@ -6508,7 +6508,7 @@ error:
|
||||
struct dns_socket *dns_so_open(const struct sockaddr *local, int type, const struct dns_options *opts, int *error) {
|
||||
struct dns_socket *so;
|
||||
|
||||
if (!(so = malloc(sizeof *so)))
|
||||
if (!(so = mem_malloc(sizeof *so)))
|
||||
goto syerr;
|
||||
|
||||
if (!dns_so_init(so, local, type, opts, error))
|
||||
@ -6536,7 +6536,7 @@ void dns_so_close(struct dns_socket *so) {
|
||||
|
||||
dns_so_destroy(so);
|
||||
|
||||
free(so);
|
||||
mem_free(so);
|
||||
} /* dns_so_close() */
|
||||
|
||||
|
||||
@ -6558,7 +6558,7 @@ static int dns_so_newanswer(struct dns_socket *so, size_t len) {
|
||||
size_t size = offsetof(struct dns_packet, data) + DNS_PP_MAX(len, DNS_SO_MINBUF);
|
||||
void *p;
|
||||
|
||||
if (!(p = realloc(so->answer, size)))
|
||||
if (!(p = mem_realloc(so->answer, size)))
|
||||
return dns_syerr();
|
||||
|
||||
so->answer = dns_p_init(p, size);
|
||||
@ -7105,7 +7105,7 @@ struct dns_resolver *dns_res_open(struct dns_resolv_conf *resconf, struct dns_ho
|
||||
goto _error;
|
||||
}
|
||||
|
||||
if (!(R = malloc(sizeof *R)))
|
||||
if (!(R = mem_malloc(sizeof *R)))
|
||||
goto syerr;
|
||||
|
||||
*R = R_initializer;
|
||||
@ -7237,7 +7237,7 @@ void dns_res_close(struct dns_resolver *R) {
|
||||
dns_resconf_close(R->resconf);
|
||||
dns_cache_close(R->cache);
|
||||
|
||||
free(R);
|
||||
mem_free(R);
|
||||
} /* dns_res_close() */
|
||||
|
||||
|
||||
@ -8274,7 +8274,7 @@ struct dns_addrinfo *dns_ai_open(const char *host, const char *serv, enum dns_ty
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(ai = malloc(sizeof *ai)))
|
||||
if (!(ai = mem_malloc(sizeof *ai)))
|
||||
goto syerr;
|
||||
|
||||
*ai = ai_initializer;
|
||||
@ -8345,7 +8345,7 @@ void dns_ai_close(struct dns_addrinfo *ai) {
|
||||
dns_p_free(ai->glue);
|
||||
|
||||
dns_p_free(ai->answer);
|
||||
free(ai);
|
||||
mem_free(ai);
|
||||
} /* dns_ai_close() */
|
||||
|
||||
|
||||
@ -8387,7 +8387,7 @@ static int dns_ai_setent(struct addrinfo **ent, union dns_any *any, enum dns_typ
|
||||
clen = 0;
|
||||
}
|
||||
|
||||
if (!(*ent = malloc(sizeof **ent + dns_sa_len(saddr) + ((ai->hints.ai_flags & AI_CANONNAME)? clen + 1 : 0))))
|
||||
if (!(*ent = mem_malloc(sizeof **ent + dns_sa_len(saddr) + ((ai->hints.ai_flags & AI_CANONNAME)? clen + 1 : 0))))
|
||||
return dns_syerr();
|
||||
|
||||
memset(*ent, '\0', sizeof **ent);
|
||||
@ -9050,7 +9050,7 @@ DNS_NORETURN static void panic(const char *fmt, ...) {
|
||||
static void *grow(unsigned char *p, size_t size) {
|
||||
void *tmp;
|
||||
|
||||
if (!(tmp = realloc(p, size)))
|
||||
if (!(tmp = mem_realloc(p, size)))
|
||||
panic("realloc(%"PRIuZ"): %s", size,
|
||||
dns_strerror(acl_fiber_last_error()));
|
||||
|
||||
@ -9356,9 +9356,9 @@ static int expand_domain(int argc, char *argv[]) {
|
||||
fwrite(dst, 1, len, stdout);
|
||||
fflush(stdout);
|
||||
|
||||
free(src);
|
||||
free(dst);
|
||||
free(pkt);
|
||||
mem_free(src);
|
||||
mem_free(dst);
|
||||
mem_free(pkt);
|
||||
|
||||
return 0;
|
||||
} /* expand_domain() */
|
||||
@ -9457,7 +9457,7 @@ static int query_hosts(int argc, char *argv[]) {
|
||||
|
||||
print_packet(A, stdout);
|
||||
|
||||
free(A);
|
||||
mem_free(A);
|
||||
|
||||
return 0;
|
||||
} /* query_hosts() */
|
||||
@ -9648,7 +9648,7 @@ static int show_hints(int argc, char *argv[]) {
|
||||
|
||||
print_packet(answer, stdout);
|
||||
|
||||
free(answer);
|
||||
mem_free(answer);
|
||||
}
|
||||
|
||||
dns_hints_close(hints);
|
||||
@ -9689,7 +9689,7 @@ static int resolve_query(int argc DNS_NOTUSED, char *argv[]) {
|
||||
|
||||
ans = dns_res_fetch(R, &error);
|
||||
print_packet(ans, stdout);
|
||||
free(ans);
|
||||
mem_free(ans);
|
||||
|
||||
st = dns_res_stat(R);
|
||||
putchar('\n');
|
||||
@ -9734,7 +9734,7 @@ static int resolve_addrinfo(int argc DNS_NOTUSED, char *argv[]) {
|
||||
|
||||
fputs(pretty, stdout);
|
||||
|
||||
free(ent);
|
||||
mem_free(ent);
|
||||
|
||||
break;
|
||||
case ENOENT:
|
||||
|
@ -54,8 +54,8 @@ static void epoll_free(EVENT *ev)
|
||||
EVENT_EPOLL *ep = (EVENT_EPOLL *) ev;
|
||||
|
||||
close(ep->epfd);
|
||||
free(ep->events);
|
||||
free(ep);
|
||||
mem_free(ep->events);
|
||||
mem_free(ep);
|
||||
}
|
||||
|
||||
static int epoll_add_read(EVENT_EPOLL *ep, FILE_EVENT *fe)
|
||||
@ -258,14 +258,14 @@ static const char *epoll_name(void)
|
||||
|
||||
EVENT *event_epoll_create(int size)
|
||||
{
|
||||
EVENT_EPOLL *ep = (EVENT_EPOLL *) calloc(1, sizeof(EVENT_EPOLL));
|
||||
EVENT_EPOLL *ep = (EVENT_EPOLL *) mem_calloc(1, sizeof(EVENT_EPOLL));
|
||||
|
||||
if (__sys_epoll_create == NULL) {
|
||||
hook_init();
|
||||
}
|
||||
|
||||
ep->events = (struct epoll_event *)
|
||||
malloc(sizeof(struct epoll_event) * size);
|
||||
mem_malloc(sizeof(struct epoll_event) * size);
|
||||
ep->size = size;
|
||||
|
||||
ep->epfd = __sys_epoll_create(1024);
|
||||
|
@ -88,7 +88,7 @@ static int iocp_close_sock(EVENT_IOCP *ev, FILE_EVENT *fe)
|
||||
* the GetQueuedCompletionStatus process.
|
||||
*/
|
||||
if (ok) {
|
||||
free(fe->reader);
|
||||
mem_free(fe->reader);
|
||||
} else {
|
||||
fe->reader->type = IOCP_EVENT_DEAD;
|
||||
fe->reader->fe = NULL;
|
||||
@ -102,7 +102,7 @@ static int iocp_close_sock(EVENT_IOCP *ev, FILE_EVENT *fe)
|
||||
* the GetQueuedCompletionStatus process.
|
||||
*/
|
||||
if (HasOverlappedIoCompleted(&fe->writer->overlapped)) {
|
||||
free(fe->writer);
|
||||
mem_free(fe->writer);
|
||||
} else {
|
||||
fe->writer->type = IOCP_EVENT_DEAD;
|
||||
fe->writer->fe = NULL;
|
||||
@ -180,7 +180,7 @@ static int iocp_add_read(EVENT_IOCP *ev, FILE_EVENT *fe)
|
||||
iocp_check(ev, fe);
|
||||
|
||||
if (fe->reader == NULL) {
|
||||
fe->reader = (IOCP_EVENT*) malloc(sizeof(IOCP_EVENT));
|
||||
fe->reader = (IOCP_EVENT*) mem_malloc(sizeof(IOCP_EVENT));
|
||||
fe->reader->fe = fe;
|
||||
}
|
||||
|
||||
@ -282,7 +282,7 @@ static int iocp_add_write(EVENT_IOCP *ev, FILE_EVENT *fe)
|
||||
iocp_check(ev, fe);
|
||||
|
||||
if (fe->writer == NULL) {
|
||||
fe->writer = (IOCP_EVENT*) malloc(sizeof(IOCP_EVENT));
|
||||
fe->writer = (IOCP_EVENT*) mem_malloc(sizeof(IOCP_EVENT));
|
||||
fe->writer->fe = fe;
|
||||
}
|
||||
|
||||
@ -378,7 +378,7 @@ static int iocp_wait(EVENT *ev, int timeout)
|
||||
}
|
||||
|
||||
if (event->type & IOCP_EVENT_DEAD) {
|
||||
free(event);
|
||||
mem_free(event);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -421,8 +421,8 @@ static void iocp_free(EVENT *ev)
|
||||
}
|
||||
array_free(ei->readers, NULL);
|
||||
array_free(ei->writers, NULL);
|
||||
free(ei->files);
|
||||
free(ei);
|
||||
mem_free(ei->files);
|
||||
mem_free(ei);
|
||||
}
|
||||
|
||||
static int iocp_checkfd(EVENT_IOCP *ev, FILE_EVENT *fe)
|
||||
@ -444,7 +444,7 @@ static const char *iocp_name(void)
|
||||
|
||||
EVENT *event_iocp_create(int size)
|
||||
{
|
||||
EVENT_IOCP *ei = (EVENT_IOCP *) calloc(1, sizeof(EVENT_IOCP));
|
||||
EVENT_IOCP *ei = (EVENT_IOCP *) mem_calloc(1, sizeof(EVENT_IOCP));
|
||||
|
||||
ei->h_iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0);
|
||||
if (ei->h_iocp == NULL) {
|
||||
@ -454,7 +454,7 @@ EVENT *event_iocp_create(int size)
|
||||
ei->readers = array_create(100);
|
||||
ei->writers = array_create(100);
|
||||
|
||||
ei->files = (FILE_EVENT**) calloc(size, sizeof(FILE_EVENT*));
|
||||
ei->files = (FILE_EVENT**) mem_calloc(size, sizeof(FILE_EVENT*));
|
||||
ei->size = size;
|
||||
ei->count = 0;
|
||||
|
||||
|
@ -50,9 +50,9 @@ static void kqueue_free(EVENT *ev)
|
||||
EVENT_KQUEUE *ek = (EVENT_KQUEUE *) ev;
|
||||
|
||||
close(ek->kqfd);
|
||||
free(ek->changes);
|
||||
free(ek->events);
|
||||
free(ek);
|
||||
mem_free(ek->changes);
|
||||
mem_free(ek->events);
|
||||
mem_free(ek);
|
||||
}
|
||||
|
||||
static int kqueue_fflush(EVENT_KQUEUE *ek)
|
||||
@ -209,7 +209,7 @@ static const char *kqueue_name(void)
|
||||
|
||||
EVENT *event_kqueue_create(int size)
|
||||
{
|
||||
EVENT_KQUEUE *ek = (EVENT_KQUEUE *) calloc(1, sizeof(EVENT_KQUEUE));
|
||||
EVENT_KQUEUE *ek = (EVENT_KQUEUE *) mem_calloc(1, sizeof(EVENT_KQUEUE));
|
||||
|
||||
if (__sys_kqueue == NULL) {
|
||||
hook_init();
|
||||
@ -218,12 +218,12 @@ EVENT *event_kqueue_create(int size)
|
||||
if (size <= 0 || size > 1024) {
|
||||
size = 1024;
|
||||
}
|
||||
ek->changes = (struct kevent *) malloc(sizeof(struct kevent) * size);
|
||||
ek->changes = (struct kevent *) mem_malloc(sizeof(struct kevent) * size);
|
||||
ek->setsize = size;
|
||||
ek->nchanges = 0;
|
||||
|
||||
ek->nevents = 100;
|
||||
ek->events = (struct kevent *) malloc(sizeof(struct kevent) * ek->nevents);
|
||||
ek->events = (struct kevent *) mem_malloc(sizeof(struct kevent) * ek->nevents);
|
||||
|
||||
ek->kqfd = __sys_kqueue();
|
||||
assert(ek->kqfd >= 0);
|
||||
|
@ -48,10 +48,10 @@ static void poll_free(EVENT *ev)
|
||||
{
|
||||
EVENT_POLL *ep = (EVENT_POLL *) ev;
|
||||
|
||||
free(ep->files);
|
||||
free(ep->pfds);
|
||||
mem_free(ep->files);
|
||||
mem_free(ep->pfds);
|
||||
array_free(ep->ready, NULL);
|
||||
free(ep);
|
||||
mem_free(ep);
|
||||
}
|
||||
|
||||
static int poll_add_read(EVENT_POLL *ep, FILE_EVENT *fe)
|
||||
@ -229,7 +229,7 @@ static const char *poll_name(void)
|
||||
|
||||
EVENT *event_poll_create(int size)
|
||||
{
|
||||
EVENT_POLL *ep = (EVENT_POLL *) calloc(1, sizeof(EVENT_POLL));
|
||||
EVENT_POLL *ep = (EVENT_POLL *) mem_calloc(1, sizeof(EVENT_POLL));
|
||||
|
||||
if (__sys_poll == NULL) {
|
||||
hook_init();
|
||||
@ -238,8 +238,8 @@ EVENT *event_poll_create(int size)
|
||||
// override size with system open limit setting
|
||||
size = open_limit(0);
|
||||
ep->size = size;
|
||||
ep->pfds = (struct pollfd *) calloc(size, sizeof(struct pollfd));
|
||||
ep->files = (FILE_EVENT**) calloc(size, sizeof(FILE_EVENT*));
|
||||
ep->pfds = (struct pollfd *) mem_calloc(size, sizeof(struct pollfd));
|
||||
ep->files = (FILE_EVENT**) mem_calloc(size, sizeof(FILE_EVENT*));
|
||||
ep->ready = array_create(100);
|
||||
ep->count = 0;
|
||||
|
||||
|
@ -52,9 +52,9 @@ typedef struct EVENT_SELECT {
|
||||
static void select_free(EVENT *ev)
|
||||
{
|
||||
EVENT_SELECT *es = (EVENT_SELECT *) ev;
|
||||
free(es->files);
|
||||
mem_free(es->files);
|
||||
array_free(es->ready, NULL);
|
||||
free(es);
|
||||
mem_free(es);
|
||||
}
|
||||
|
||||
static int select_add_read(EVENT_SELECT *es, FILE_EVENT *fe)
|
||||
@ -234,7 +234,7 @@ static const char *select_name(void)
|
||||
|
||||
EVENT *event_select_create(int size)
|
||||
{
|
||||
EVENT_SELECT *es = (EVENT_SELECT *) calloc(1, sizeof(EVENT_SELECT));
|
||||
EVENT_SELECT *es = (EVENT_SELECT *) mem_calloc(1, sizeof(EVENT_SELECT));
|
||||
|
||||
if (__sys_select == NULL) {
|
||||
hook_init();
|
||||
@ -244,7 +244,7 @@ EVENT *event_select_create(int size)
|
||||
size = open_limit(0);
|
||||
es->maxfd = -1;
|
||||
es->dirty = 0;
|
||||
es->files = (FILE_EVENT**) calloc(size, sizeof(FILE_EVENT*));
|
||||
es->files = (FILE_EVENT**) mem_calloc(size, sizeof(FILE_EVENT*));
|
||||
es->size = size;
|
||||
es->ready = array_create(100);
|
||||
es->count = 0;
|
||||
|
@ -59,8 +59,8 @@ static void wmsg_free(EVENT *ev)
|
||||
}
|
||||
}
|
||||
htable_free(ew->tbl, NULL);
|
||||
free(ew->files);
|
||||
free(ew);
|
||||
mem_free(ew->files);
|
||||
mem_free(ew);
|
||||
}
|
||||
|
||||
static void wmsg_fdmap_set(EVENT_WMSG *ev, FILE_EVENT *fe)
|
||||
@ -420,11 +420,11 @@ static const char *__class_name = "__AclFiberEventsMainWClass";
|
||||
|
||||
EVENT *event_wmsg_create(int size)
|
||||
{
|
||||
EVENT_WMSG *ew = (EVENT_WMSG *) calloc(1, sizeof(EVENT_WMSG));
|
||||
EVENT_WMSG *ew = (EVENT_WMSG *) mem_calloc(1, sizeof(EVENT_WMSG));
|
||||
HINSTANCE hInstance = GetModuleHandle(NULL);
|
||||
HWND hWnd = CreateSockWindow(__class_name, hInstance);
|
||||
|
||||
ew->files = (FILE_EVENT**) calloc(size, sizeof(FILE_EVENT*));
|
||||
ew->files = (FILE_EVENT**) mem_calloc(size, sizeof(FILE_EVENT*));
|
||||
ew->size = size;
|
||||
ew->count = 0;
|
||||
|
||||
|
@ -110,11 +110,11 @@ static void thread_free(void *ctx)
|
||||
}
|
||||
|
||||
if (tf->fibers) {
|
||||
free(tf->fibers);
|
||||
mem_free(tf->fibers);
|
||||
}
|
||||
|
||||
tf->original->free_fn(tf->original);
|
||||
free(tf);
|
||||
mem_free(tf);
|
||||
|
||||
if (__main_fiber == __thread_fiber) {
|
||||
__main_fiber = NULL;
|
||||
@ -155,7 +155,7 @@ static void fiber_check(void)
|
||||
__FILE__, __LINE__, __FUNCTION__, last_serror());
|
||||
}
|
||||
|
||||
__thread_fiber = (THREAD *) calloc(1, sizeof(THREAD));
|
||||
__thread_fiber = (THREAD *) mem_calloc(1, sizeof(THREAD));
|
||||
|
||||
__thread_fiber->original = __fiber_origin_fn();
|
||||
__thread_fiber->fibers = NULL;
|
||||
@ -383,7 +383,7 @@ static void check_timer(ACL_FIBER *fiber fiber_unused, void *ctx)
|
||||
size_t *intptr = (size_t *) ctx;
|
||||
size_t max = *intptr;
|
||||
|
||||
free(intptr);
|
||||
mem_free(intptr);
|
||||
while (1) {
|
||||
#ifdef SYS_WIN
|
||||
Sleep(1000);
|
||||
@ -396,7 +396,7 @@ static void check_timer(ACL_FIBER *fiber fiber_unused, void *ctx)
|
||||
|
||||
void acl_fiber_check_timer(size_t max)
|
||||
{
|
||||
size_t *intptr = (size_t *) malloc(sizeof(int));
|
||||
size_t *intptr = (size_t *) mem_malloc(sizeof(int));
|
||||
|
||||
*intptr = max;
|
||||
acl_fiber_create(check_timer, intptr, 64000);
|
||||
@ -556,7 +556,7 @@ static void fbase_finish(FIBER_BASE *fbase)
|
||||
|
||||
FIBER_BASE *fbase_alloc(void)
|
||||
{
|
||||
FIBER_BASE *fbase = (FIBER_BASE *) calloc(1, sizeof(FIBER_BASE));
|
||||
FIBER_BASE *fbase = (FIBER_BASE *) mem_calloc(1, sizeof(FIBER_BASE));
|
||||
|
||||
fbase_init(fbase, FBASE_F_BASE);
|
||||
return fbase;
|
||||
@ -565,7 +565,7 @@ FIBER_BASE *fbase_alloc(void)
|
||||
void fbase_free(FIBER_BASE *fbase)
|
||||
{
|
||||
fbase_finish(fbase);
|
||||
free(fbase);
|
||||
mem_free(fbase);
|
||||
}
|
||||
|
||||
void fiber_free(ACL_FIBER *fiber)
|
||||
@ -587,11 +587,11 @@ static void fiber_start(ACL_FIBER *fiber)
|
||||
if (fiber->locals[i]->free_fn) {
|
||||
fiber->locals[i]->free_fn(fiber->locals[i]->ctx);
|
||||
}
|
||||
free(fiber->locals[i]);
|
||||
mem_free(fiber->locals[i]);
|
||||
}
|
||||
|
||||
if (fiber->locals) {
|
||||
free(fiber->locals);
|
||||
mem_free(fiber->locals);
|
||||
fiber->locals = NULL;
|
||||
fiber->nlocal = 0;
|
||||
}
|
||||
@ -601,7 +601,7 @@ static void fiber_start(ACL_FIBER *fiber)
|
||||
|
||||
ACL_FIBER *acl_fiber_alloc(size_t size, void **pptr)
|
||||
{
|
||||
ACL_FIBER *fiber = (ACL_FIBER *) calloc(1, sizeof(ACL_FIBER) + size);
|
||||
ACL_FIBER *fiber = (ACL_FIBER *) mem_calloc(1, sizeof(ACL_FIBER) + size);
|
||||
*pptr = ((char*) fiber) + sizeof(ACL_FIBER);
|
||||
return fiber;
|
||||
}
|
||||
@ -659,7 +659,7 @@ ACL_FIBER *acl_fiber_create(void (*fn)(ACL_FIBER *, void *),
|
||||
|
||||
if (__thread_fiber->slot >= __thread_fiber->size) {
|
||||
__thread_fiber->size += 128;
|
||||
__thread_fiber->fibers = (ACL_FIBER **) realloc(
|
||||
__thread_fiber->fibers = (ACL_FIBER **) mem_realloc(
|
||||
__thread_fiber->fibers,
|
||||
__thread_fiber->size * sizeof(ACL_FIBER *));
|
||||
}
|
||||
@ -825,13 +825,13 @@ int acl_fiber_set_specific(int *key, void *ctx, void (*free_fn)(void *))
|
||||
if (curr->nlocal < __thread_fiber->nlocal) {
|
||||
int i, n = curr->nlocal;
|
||||
curr->nlocal = __thread_fiber->nlocal;
|
||||
curr->locals = (FIBER_LOCAL **) realloc(curr->locals,
|
||||
curr->locals = (FIBER_LOCAL **) mem_realloc(curr->locals,
|
||||
curr->nlocal * sizeof(FIBER_LOCAL*));
|
||||
for (i = n; i < curr->nlocal; i++)
|
||||
curr->locals[i] = NULL;
|
||||
}
|
||||
|
||||
local = (FIBER_LOCAL *) calloc(1, sizeof(FIBER_LOCAL));
|
||||
local = (FIBER_LOCAL *) mem_calloc(1, sizeof(FIBER_LOCAL));
|
||||
local->ctx = ctx;
|
||||
local->free_fn = free_fn;
|
||||
curr->locals[*key - 1] = local;
|
||||
@ -888,3 +888,8 @@ void acl_fiber_set_error(int errnum)
|
||||
#endif
|
||||
errno = errnum;
|
||||
}
|
||||
|
||||
void acl_fiber_memstat(void)
|
||||
{
|
||||
mem_stat();
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ static void fiber_unix_free(ACL_FIBER *fiber)
|
||||
stack_free(fb->context);
|
||||
}
|
||||
stack_free(fb->buff);
|
||||
free(fb);
|
||||
mem_free(fb);
|
||||
}
|
||||
|
||||
union cc_arg
|
||||
@ -236,7 +236,7 @@ static void fiber_unix_init(ACL_FIBER *fiber, size_t size)
|
||||
|
||||
ACL_FIBER *fiber_unix_alloc(void (*start_fn)(ACL_FIBER *), size_t size)
|
||||
{
|
||||
FIBER_UNIX *fb = (FIBER_UNIX *) calloc(1, sizeof(*fb));
|
||||
FIBER_UNIX *fb = (FIBER_UNIX *) mem_calloc(1, sizeof(*fb));
|
||||
|
||||
/* no using calloc just avoiding using real memory */
|
||||
fb->buff = (char *) stack_alloc(size);
|
||||
@ -251,7 +251,7 @@ ACL_FIBER *fiber_unix_alloc(void (*start_fn)(ACL_FIBER *), size_t size)
|
||||
|
||||
ACL_FIBER *fiber_unix_origin(void)
|
||||
{
|
||||
FIBER_UNIX *fb = (FIBER_UNIX *)calloc(1, sizeof(*fb));
|
||||
FIBER_UNIX *fb = (FIBER_UNIX *) mem_calloc(1, sizeof(*fb));
|
||||
|
||||
#ifdef USE_JMP
|
||||
/* set context NULL when using setjmp that setcontext will not be
|
||||
|
@ -43,7 +43,7 @@ static void fiber_win_init(FIBER_WIN *fb, size_t size)
|
||||
|
||||
ACL_FIBER *fiber_win_alloc(void (*start_fn)(ACL_FIBER *), size_t size)
|
||||
{
|
||||
FIBER_WIN *fb = (FIBER_WIN *) calloc(1, sizeof(*fb));
|
||||
FIBER_WIN *fb = (FIBER_WIN *) mem_calloc(1, sizeof(*fb));
|
||||
|
||||
fb->fiber.init_fn = (void (*)(ACL_FIBER*, size_t)) fiber_win_init;
|
||||
fb->fiber.free_fn = fiber_win_free;
|
||||
@ -56,7 +56,7 @@ ACL_FIBER *fiber_win_alloc(void (*start_fn)(ACL_FIBER *), size_t size)
|
||||
|
||||
ACL_FIBER *fiber_win_origin(void)
|
||||
{
|
||||
FIBER_WIN *fb = (FIBER_WIN *) calloc(1, sizeof(*fb));
|
||||
FIBER_WIN *fb = (FIBER_WIN *) mem_calloc(1, sizeof(*fb));
|
||||
|
||||
fb->context = ConvertThreadToFiberEx(NULL, FIBER_FLAG_FLOAT_SWITCH);
|
||||
fb->fiber.free_fn = fiber_win_free;
|
||||
|
@ -18,7 +18,7 @@ ACL_FIBER_COND *acl_fiber_cond_create(unsigned flag fiber_unused)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
ACL_FIBER_COND *cond = (ACL_FIBER_COND *)
|
||||
calloc(1, sizeof(ACL_FIBER_COND));
|
||||
mem_calloc(1, sizeof(ACL_FIBER_COND));
|
||||
|
||||
ring_init(&cond->waiters);
|
||||
cond->atomic = atomic_new();
|
||||
@ -37,7 +37,7 @@ void acl_fiber_cond_free(ACL_FIBER_COND *cond)
|
||||
{
|
||||
pthread_mutex_destroy(&cond->mutex);
|
||||
atomic_free(cond->atomic);
|
||||
free(cond);
|
||||
mem_free(cond);
|
||||
}
|
||||
|
||||
static void __ll_lock(ACL_FIBER_COND *cond)
|
||||
|
@ -46,7 +46,7 @@ static void event_ferror(ACL_FIBER_EVENT* event, const char* fmt, ...)
|
||||
ACL_FIBER_EVENT *acl_fiber_event_create(unsigned flag)
|
||||
{
|
||||
ACL_FIBER_EVENT *event = (ACL_FIBER_EVENT *)
|
||||
calloc(1, sizeof(ACL_FIBER_EVENT));
|
||||
mem_calloc(1, sizeof(ACL_FIBER_EVENT));
|
||||
|
||||
event->owner = NULL;
|
||||
event->tid = 0;
|
||||
@ -81,7 +81,7 @@ void acl_fiber_event_free(ACL_FIBER_EVENT *event)
|
||||
atomic_free(event->lock.atomic.alock);
|
||||
}
|
||||
|
||||
free(event);
|
||||
mem_free(event);
|
||||
}
|
||||
|
||||
static inline void __ll_lock(ACL_FIBER_EVENT *event)
|
||||
|
@ -60,10 +60,10 @@ static void thread_free(void *ctx)
|
||||
#ifdef SYS_WIN
|
||||
htable_free(tf->events, NULL);
|
||||
#else
|
||||
free(tf->events);
|
||||
mem_free(tf->events);
|
||||
#endif
|
||||
|
||||
free(tf);
|
||||
mem_free(tf);
|
||||
|
||||
if (__main_fiber == __thread_fiber) {
|
||||
__main_fiber = NULL;
|
||||
@ -117,7 +117,7 @@ void fiber_io_check(void)
|
||||
var_maxfd = MAXFD;
|
||||
}
|
||||
|
||||
__thread_fiber = (FIBER_TLS *) malloc(sizeof(FIBER_TLS));
|
||||
__thread_fiber = (FIBER_TLS *) mem_malloc(sizeof(FIBER_TLS));
|
||||
__thread_fiber->event = event_create(var_maxfd);
|
||||
__thread_fiber->ev_fiber = acl_fiber_create(fiber_io_loop,
|
||||
__thread_fiber->event, STACK_SIZE);
|
||||
@ -130,7 +130,7 @@ void fiber_io_check(void)
|
||||
__thread_fiber->events = htable_create(var_maxfd);
|
||||
#else
|
||||
__thread_fiber->events = (FILE_EVENT **)
|
||||
calloc(var_maxfd, sizeof(FILE_EVENT*));
|
||||
mem_calloc(var_maxfd, sizeof(FILE_EVENT*));
|
||||
#endif
|
||||
|
||||
if (__pthread_self() == main_thread_self()) {
|
||||
|
@ -19,7 +19,7 @@ struct ACL_FIBER_RWLOCK {
|
||||
|
||||
ACL_FIBER_MUTEX *acl_fiber_mutex_create(void)
|
||||
{
|
||||
ACL_FIBER_MUTEX *lk = (ACL_FIBER_MUTEX *) malloc(sizeof(ACL_FIBER_MUTEX));
|
||||
ACL_FIBER_MUTEX *lk = (ACL_FIBER_MUTEX *) mem_malloc(sizeof(ACL_FIBER_MUTEX));
|
||||
|
||||
lk->owner = NULL;
|
||||
ring_init(&lk->me);
|
||||
@ -29,7 +29,7 @@ ACL_FIBER_MUTEX *acl_fiber_mutex_create(void)
|
||||
|
||||
void acl_fiber_mutex_free(ACL_FIBER_MUTEX *lk)
|
||||
{
|
||||
free(lk);
|
||||
mem_free(lk);
|
||||
}
|
||||
|
||||
static int __lock(ACL_FIBER_MUTEX *lk, int block)
|
||||
@ -119,7 +119,7 @@ void acl_fiber_mutex_unlock(ACL_FIBER_MUTEX *lk)
|
||||
ACL_FIBER_RWLOCK *acl_fiber_rwlock_create(void)
|
||||
{
|
||||
ACL_FIBER_RWLOCK *lk = (ACL_FIBER_RWLOCK *)
|
||||
malloc(sizeof(ACL_FIBER_RWLOCK));
|
||||
mem_malloc(sizeof(ACL_FIBER_RWLOCK));
|
||||
|
||||
lk->readers = 0;
|
||||
lk->writer = NULL;
|
||||
@ -131,7 +131,7 @@ ACL_FIBER_RWLOCK *acl_fiber_rwlock_create(void)
|
||||
|
||||
void acl_fiber_rwlock_free(ACL_FIBER_RWLOCK *lk)
|
||||
{
|
||||
free(lk);
|
||||
mem_free(lk);
|
||||
}
|
||||
|
||||
static int __rlock(ACL_FIBER_RWLOCK *lk, int block)
|
||||
|
@ -12,7 +12,7 @@ struct ACL_FIBER_SEM {
|
||||
|
||||
ACL_FIBER_SEM *acl_fiber_sem_create(int num)
|
||||
{
|
||||
ACL_FIBER_SEM *sem = (ACL_FIBER_SEM *) malloc(sizeof(ACL_FIBER_SEM));
|
||||
ACL_FIBER_SEM *sem = (ACL_FIBER_SEM *) mem_malloc(sizeof(ACL_FIBER_SEM));
|
||||
|
||||
sem->tid = 0;
|
||||
sem->num = num;
|
||||
@ -22,7 +22,7 @@ ACL_FIBER_SEM *acl_fiber_sem_create(int num)
|
||||
|
||||
void acl_fiber_sem_free(ACL_FIBER_SEM *sem)
|
||||
{
|
||||
free(sem);
|
||||
mem_free(sem);
|
||||
}
|
||||
|
||||
unsigned long acl_fiber_sem_get_tid(ACL_FIBER_SEM *sem)
|
||||
|
@ -31,12 +31,12 @@ void file_event_init(FILE_EVENT *fe, socket_t fd)
|
||||
|
||||
FILE_EVENT *file_event_alloc(socket_t fd)
|
||||
{
|
||||
FILE_EVENT *fe = (FILE_EVENT *) calloc(1, sizeof(FILE_EVENT));
|
||||
FILE_EVENT *fe = (FILE_EVENT *) mem_calloc(1, sizeof(FILE_EVENT));
|
||||
file_event_init(fe, fd);
|
||||
return fe;
|
||||
}
|
||||
|
||||
void file_event_free(FILE_EVENT *fe)
|
||||
{
|
||||
free(fe);
|
||||
mem_free(fe);
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ static void hook_init(void)
|
||||
|
||||
static EPOLL_EVENT *epfd_alloc(void)
|
||||
{
|
||||
EPOLL_EVENT *ee = calloc(1, sizeof(EPOLL_EVENT));
|
||||
EPOLL_EVENT *ee = mem_calloc(1, sizeof(EPOLL_EVENT));
|
||||
int maxfd = open_limit(0);
|
||||
|
||||
if (maxfd <= 0) {
|
||||
@ -54,7 +54,7 @@ static EPOLL_EVENT *epfd_alloc(void)
|
||||
}
|
||||
|
||||
++maxfd;
|
||||
ee->fds = (EPOLL_CTX **) malloc(maxfd * sizeof(EPOLL_CTX *));
|
||||
ee->fds = (EPOLL_CTX **) mem_malloc(maxfd * sizeof(EPOLL_CTX *));
|
||||
ee->nfds = maxfd;
|
||||
|
||||
return ee;
|
||||
@ -84,7 +84,7 @@ static void thread_free(void *ctx fiber_unused)
|
||||
|
||||
for (j = 0; j < ee->nfds; j++) {
|
||||
if (ee->fds[j] != NULL) {
|
||||
free(ee->fds[j]);
|
||||
mem_free(ee->fds[j]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,8 +92,8 @@ static void thread_free(void *ctx fiber_unused)
|
||||
fiber_save_errno(acl_fiber_last_error());
|
||||
}
|
||||
|
||||
free(ee->fds);
|
||||
free(ee);
|
||||
mem_free(ee->fds);
|
||||
mem_free(ee);
|
||||
}
|
||||
|
||||
array_free(__epfds, NULL);
|
||||
@ -200,12 +200,12 @@ int epoll_event_close(int epfd)
|
||||
|
||||
for (i = 0; i < ee->nfds; i++) {
|
||||
if (ee->fds[i] != NULL) {
|
||||
free(ee->fds[i]);
|
||||
mem_free(ee->fds[i]);
|
||||
}
|
||||
}
|
||||
|
||||
free(ee->fds);
|
||||
free(ee);
|
||||
mem_free(ee->fds);
|
||||
mem_free(ee);
|
||||
array_delete(__epfds, pos, NULL);
|
||||
|
||||
return __sys_close(epfd);
|
||||
@ -295,8 +295,7 @@ static void epoll_ctl_add(EVENT *ev, EPOLL_EVENT *ee,
|
||||
struct epoll_event *event, int fd, int op)
|
||||
{
|
||||
if (ee->fds[fd] == NULL) {
|
||||
ee->fds[fd] = (EPOLL_CTX *)
|
||||
malloc(sizeof(EPOLL_CTX));
|
||||
ee->fds[fd] = (EPOLL_CTX *) mem_malloc(sizeof(EPOLL_CTX));
|
||||
}
|
||||
|
||||
ee->fds[fd]->fd = fd;
|
||||
@ -334,7 +333,7 @@ static void epoll_ctl_del(EVENT *ev, EPOLL_EVENT *ee, int fd)
|
||||
ee->fds[fd]->fe = NULL;
|
||||
memset(&ee->fds[fd]->data, 0, sizeof(ee->fds[fd]->data));
|
||||
|
||||
free(ee->fds[fd]);
|
||||
mem_free(ee->fds[fd]);
|
||||
ee->fds[fd] = NULL;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ static struct addrinfo *create_addrinfo(const char *ip, short port,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
res = (struct addrinfo *) calloc(1, sizeof(*res) + addrlen);
|
||||
res = (struct addrinfo *) mem_calloc(1, sizeof(*res) + addrlen);
|
||||
res->ai_family = sa.sa.sa_family;
|
||||
res->ai_socktype = socktype;
|
||||
res->ai_flags = flags;
|
||||
@ -110,7 +110,7 @@ static void saveaddrinfo(struct dns_addrinfo *ai, struct addrinfo **res)
|
||||
&& ent->ai_family != AF_INET6)
|
||||
#endif
|
||||
{
|
||||
free(ent);
|
||||
mem_free(ent);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -230,7 +230,7 @@ void acl_fiber_freeaddrinfo(struct addrinfo *res)
|
||||
while (res) {
|
||||
struct addrinfo *tmp = res;
|
||||
res = res->ai_next;
|
||||
free(tmp);
|
||||
mem_free(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ static void hook_init(void)
|
||||
|
||||
static void free_fn(void *ctx)
|
||||
{
|
||||
free(ctx);
|
||||
mem_free(ctx);
|
||||
}
|
||||
|
||||
struct hostent *acl_fiber_gethostbyname(const char *name)
|
||||
@ -64,14 +64,14 @@ struct hostent *acl_fiber_gethostbyname(const char *name)
|
||||
|
||||
fiber_buf = (char *) acl_fiber_get_specific(__fiber_buf_key);
|
||||
if (fiber_buf == NULL) {
|
||||
fiber_buf = (char *) malloc(BUF_LEN);
|
||||
fiber_buf = (char *) mem_malloc(BUF_LEN);
|
||||
acl_fiber_set_specific(&__fiber_buf_key, fiber_buf, free_fn);
|
||||
}
|
||||
assert(fiber_buf);
|
||||
|
||||
fiber_res = (struct hostent *) acl_fiber_get_specific(__fiber_res_key);
|
||||
if (fiber_res == NULL) {
|
||||
fiber_res = (struct hostent *) malloc(sizeof(struct hostent));
|
||||
fiber_res = (struct hostent *) mem_malloc(sizeof(struct hostent));
|
||||
acl_fiber_set_specific(&__fiber_res_key, fiber_res, free_fn);
|
||||
}
|
||||
assert(fiber_res);
|
||||
|
@ -129,7 +129,7 @@ static void poll_callback(EVENT *ev fiber_unused, POLL_EVENT *pe)
|
||||
|
||||
static POLLFD *pollfd_alloc(POLL_EVENT *pe, struct pollfd *fds, nfds_t nfds)
|
||||
{
|
||||
POLLFD *pfds = (POLLFD *) malloc(nfds * sizeof(POLLFD));
|
||||
POLLFD *pfds = (POLLFD *) mem_malloc(nfds * sizeof(POLLFD));
|
||||
nfds_t i;
|
||||
|
||||
for (i = 0; i < nfds; i++) {
|
||||
@ -143,7 +143,7 @@ static POLLFD *pollfd_alloc(POLL_EVENT *pe, struct pollfd *fds, nfds_t nfds)
|
||||
|
||||
static void pollfd_free(POLLFD *pfds)
|
||||
{
|
||||
free(pfds);
|
||||
mem_free(pfds);
|
||||
}
|
||||
|
||||
int WINAPI acl_fiber_poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||
|
@ -93,17 +93,17 @@ static struct pollfd *pfds_create(int *nfds, fd_set *readfds,
|
||||
*nfds = exceptfds->fd_count;
|
||||
}
|
||||
|
||||
fds = (struct pollfd *) calloc(*nfds + 1, sizeof(struct pollfd));
|
||||
fds = (struct pollfd *) mem_calloc(*nfds + 1, sizeof(struct pollfd));
|
||||
if (readfds && set_fdset(fds, *nfds, &cnt, readfds, POLLIN) == -1) {
|
||||
free(fds);
|
||||
mem_free(fds);
|
||||
return NULL;
|
||||
}
|
||||
if (writefds && set_fdset(fds, *nfds, &cnt, writefds, POLLOUT) == -1) {
|
||||
free(fds);
|
||||
mem_free(fds);
|
||||
return NULL;
|
||||
}
|
||||
if (exceptfds && set_fdset(fds, *nfds, &cnt, exceptfds, POLLERR) == -1) {
|
||||
free(fds);
|
||||
mem_free(fds);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -116,7 +116,7 @@ static struct pollfd *pfds_create(int *nfds, fd_set *readfds,
|
||||
int fd;
|
||||
struct pollfd *fds;
|
||||
|
||||
fds = (struct pollfd *) calloc(*nfds + 1, sizeof(struct pollfd));
|
||||
fds = (struct pollfd *) mem_calloc(*nfds + 1, sizeof(struct pollfd));
|
||||
|
||||
for (fd = 0; fd < *nfds; fd++) {
|
||||
if (readfds && FD_ISSET(fd, readfds)) {
|
||||
@ -201,7 +201,7 @@ int acl_fiber_select(int nfds, fd_set *readfds, fd_set *writefds,
|
||||
}
|
||||
}
|
||||
|
||||
free(fds);
|
||||
mem_free(fds);
|
||||
return nready;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ static void echo_client(ACL_FIBER *fiber acl_unused, void *ctx)
|
||||
int ret;
|
||||
|
||||
__socket_count++;
|
||||
printf("client fiber-%d: fd: %d\r\n", acl_fiber_self(), fd);
|
||||
//printf("client fiber-%d: fd: %d\r\n", acl_fiber_self(), fd);
|
||||
|
||||
while (1) {
|
||||
if (__rw_timeout > 0) {
|
||||
@ -188,7 +188,7 @@ static void fiber_accept(ACL_FIBER *fiber acl_unused, void *ctx acl_unused)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#define SCHEDULE_AUTO
|
||||
//#define SCHEDULE_AUTO
|
||||
|
||||
#ifndef SCHEDULE_AUTO
|
||||
static void fiber_memcheck(ACL_FIBER *fiber acl_unused, void *ctx acl_unused)
|
||||
@ -200,6 +200,7 @@ static void fiber_memcheck(ACL_FIBER *fiber acl_unused, void *ctx acl_unused)
|
||||
sleep(1);
|
||||
#endif
|
||||
acl_default_meminfo();
|
||||
acl_fiber_memstat();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user