add files: fc_memory.[hc]
parent
ec22ab681e
commit
4aad4f78b9
5
HISTORY
5
HISTORY
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
Version 1.44 2020-06-28
|
Version 1.44 2020-07-07
|
||||||
* add test file src/tests/test_pthread_lock.c
|
* add test file src/tests/test_pthread_lock.c
|
||||||
* add uniq_skiplist.[hc]
|
* add uniq_skiplist.[hc]
|
||||||
* add function split_string_ex
|
* add function split_string_ex
|
||||||
|
|
@ -30,7 +30,8 @@ Version 1.44 2020-06-28
|
||||||
* fast_task_queue.[hc]: free_queue support init_callback
|
* fast_task_queue.[hc]: free_queue support init_callback
|
||||||
* ini_file_reader.c: use mutex lock when access dynamic content array
|
* ini_file_reader.c: use mutex lock when access dynamic content array
|
||||||
* uniq_skiplist add function uniq_skiplist_replace_ex
|
* uniq_skiplist add function uniq_skiplist_replace_ex
|
||||||
* add fc_queue.[hc]
|
* add files: fc_queue.[hc]
|
||||||
|
* add files: fc_memory.[hc]
|
||||||
|
|
||||||
Version 1.43 2019-12-25
|
Version 1.43 2019-12-25
|
||||||
* replace function call system to getExecResult,
|
* replace function call system to getExecResult,
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ FAST_SHARED_OBJS = hash.lo chain.lo shared_func.lo ini_file_reader.lo \
|
||||||
char_converter.lo char_convert_loader.lo common_blocked_queue.lo \
|
char_converter.lo char_convert_loader.lo common_blocked_queue.lo \
|
||||||
multi_socket_client.lo skiplist_set.lo uniq_skiplist.lo \
|
multi_socket_client.lo skiplist_set.lo uniq_skiplist.lo \
|
||||||
json_parser.lo buffered_file_writer.lo server_id_func.lo \
|
json_parser.lo buffered_file_writer.lo server_id_func.lo \
|
||||||
fc_queue.lo
|
fc_queue.lo fc_memory.lo
|
||||||
|
|
||||||
FAST_STATIC_OBJS = hash.o chain.o shared_func.o ini_file_reader.o \
|
FAST_STATIC_OBJS = hash.o chain.o shared_func.o ini_file_reader.o \
|
||||||
logger.o sockopt.o base64.o sched_thread.o \
|
logger.o sockopt.o base64.o sched_thread.o \
|
||||||
|
|
@ -29,7 +29,7 @@ FAST_STATIC_OBJS = hash.o chain.o shared_func.o ini_file_reader.o \
|
||||||
char_converter.o char_convert_loader.o common_blocked_queue.o \
|
char_converter.o char_convert_loader.o common_blocked_queue.o \
|
||||||
multi_socket_client.o skiplist_set.o uniq_skiplist.o \
|
multi_socket_client.o skiplist_set.o uniq_skiplist.o \
|
||||||
json_parser.o buffered_file_writer.o server_id_func.o \
|
json_parser.o buffered_file_writer.o server_id_func.o \
|
||||||
fc_queue.o
|
fc_queue.o fc_memory.o
|
||||||
|
|
||||||
HEADER_FILES = common_define.h hash.h chain.h logger.h base64.h \
|
HEADER_FILES = common_define.h hash.h chain.h logger.h base64.h \
|
||||||
shared_func.h pthread_func.h ini_file_reader.h _os_define.h \
|
shared_func.h pthread_func.h ini_file_reader.h _os_define.h \
|
||||||
|
|
@ -43,7 +43,7 @@ HEADER_FILES = common_define.h hash.h chain.h logger.h base64.h \
|
||||||
char_convert_loader.h common_blocked_queue.h \
|
char_convert_loader.h common_blocked_queue.h \
|
||||||
multi_socket_client.h skiplist_set.h uniq_skiplist.h \
|
multi_socket_client.h skiplist_set.h uniq_skiplist.h \
|
||||||
fc_list.h json_parser.h buffered_file_writer.h server_id_func.h \
|
fc_list.h json_parser.h buffered_file_writer.h server_id_func.h \
|
||||||
fc_queue.h
|
fc_queue.h fc_memory.h
|
||||||
|
|
||||||
ALL_OBJS = $(FAST_STATIC_OBJS) $(FAST_SHARED_OBJS)
|
ALL_OBJS = $(FAST_STATIC_OBJS) $(FAST_SHARED_OBJS)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include "fc_memory.h"
|
||||||
#include "avl_tree.h"
|
#include "avl_tree.h"
|
||||||
|
|
||||||
int avl_tree_init(AVLTreeInfo *tree, FreeDataFunc free_data_func, \
|
int avl_tree_init(AVLTreeInfo *tree, FreeDataFunc free_data_func, \
|
||||||
|
|
@ -45,14 +46,9 @@ void avl_tree_destroy(AVLTreeInfo *tree)
|
||||||
static AVLTreeNode *createTreeNode(AVLTreeNode *pParentNode, void *target_data)
|
static AVLTreeNode *createTreeNode(AVLTreeNode *pParentNode, void *target_data)
|
||||||
{
|
{
|
||||||
AVLTreeNode *pNewNode;
|
AVLTreeNode *pNewNode;
|
||||||
pNewNode = (AVLTreeNode *)malloc(sizeof(AVLTreeNode));
|
pNewNode = (AVLTreeNode *)fc_malloc(sizeof(AVLTreeNode));
|
||||||
if (pNewNode == NULL)
|
if (pNewNode == NULL)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
fprintf(stderr, "file: "__FILE__", line: %d, " \
|
|
||||||
"malloc %d bytes fail!\n", __LINE__, \
|
|
||||||
(int)sizeof(AVLTreeNode));
|
|
||||||
*/
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include "fc_memory.h"
|
||||||
#include "base64.h"
|
#include "base64.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -281,11 +282,9 @@ char *base64_decode_auto(struct base64_context *context, const char *src, \
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pBuff = (char *)malloc(nNewLen);
|
pBuff = (char *)fc_malloc(nNewLen);
|
||||||
if (pBuff == NULL)
|
if (pBuff == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Can't malloc %d bytes\n", \
|
|
||||||
nSrcLen + nPadLen + 1);
|
|
||||||
*dest_len = 0;
|
*dest_len = 0;
|
||||||
*dest = '\0';
|
*dest = '\0';
|
||||||
return dest;
|
return dest;
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "shared_func.h"
|
#include "shared_func.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "fc_memory.h"
|
||||||
#include "buffered_file_writer.h"
|
#include "buffered_file_writer.h"
|
||||||
|
|
||||||
int buffered_file_writer_open_ex(BufferedFileWriter *writer,
|
int buffered_file_writer_open_ex(BufferedFileWriter *writer,
|
||||||
|
|
@ -34,12 +35,9 @@ int buffered_file_writer_open_ex(BufferedFileWriter *writer,
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
writer->buff = (char *)malloc(writer->buffer_size);
|
writer->buff = (char *)fc_malloc(writer->buffer_size);
|
||||||
if (writer->buff == NULL)
|
if (writer->buff == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail",
|
|
||||||
__LINE__, writer->buffer_size);
|
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "chain.h"
|
#include "chain.h"
|
||||||
|
#include "fc_memory.h"
|
||||||
//#include "use_mmalloc.h"
|
//#include "use_mmalloc.h"
|
||||||
|
|
||||||
void chain_init(ChainList *pList, const int type, FreeDataFunc freeDataFunc, \
|
void chain_init(ChainList *pList, const int type, FreeDataFunc freeDataFunc, \
|
||||||
|
|
@ -69,7 +70,7 @@ int insertNodePrior(ChainList *pList, void *data)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pNode = (ChainNode *)malloc(sizeof(ChainNode));
|
pNode = (ChainNode *)fc_malloc(sizeof(ChainNode));
|
||||||
if (pNode == NULL)
|
if (pNode == NULL)
|
||||||
{
|
{
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
@ -95,7 +96,7 @@ int appendNode(ChainList *pList, void *data)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pNode = (ChainNode *)malloc(sizeof(ChainNode));
|
pNode = (ChainNode *)fc_malloc(sizeof(ChainNode));
|
||||||
if (pNode == NULL)
|
if (pNode == NULL)
|
||||||
{
|
{
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
@ -128,7 +129,7 @@ int insertNodeAsc(ChainList *pList, void *data)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pNew = (ChainNode *)malloc(sizeof(ChainNode));
|
pNew = (ChainNode *)fc_malloc(sizeof(ChainNode));
|
||||||
if (pNew == NULL)
|
if (pNew == NULL)
|
||||||
{
|
{
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,6 @@ static void fast_allocator_malloc_trunk_notify_func(const int alloc_bytes, void
|
||||||
static int allocator_array_check_capacity(struct fast_allocator_context *acontext,
|
static int allocator_array_check_capacity(struct fast_allocator_context *acontext,
|
||||||
const int allocator_count)
|
const int allocator_count)
|
||||||
{
|
{
|
||||||
int result;
|
|
||||||
int bytes;
|
int bytes;
|
||||||
int target_count;
|
int target_count;
|
||||||
int alloc_count;
|
int alloc_count;
|
||||||
|
|
@ -108,14 +107,10 @@ static int allocator_array_check_capacity(struct fast_allocator_context *acontex
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = sizeof(struct fast_allocator_info *) * alloc_count;
|
bytes = sizeof(struct fast_allocator_info *) * alloc_count;
|
||||||
new_allocators = (struct fast_allocator_info **)malloc(bytes);
|
new_allocators = (struct fast_allocator_info **)fc_malloc(bytes);
|
||||||
if (new_allocators == NULL)
|
if (new_allocators == NULL)
|
||||||
{
|
{
|
||||||
result = errno != 0 ? errno : ENOMEM;
|
return ENOMEM;
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail, errno: %d, error info: %s",
|
|
||||||
__LINE__, bytes, result, STRERROR(result));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (acontext->allocator_array.allocators != NULL)
|
if (acontext->allocator_array.allocators != NULL)
|
||||||
|
|
@ -144,14 +139,10 @@ static int region_init(struct fast_allocator_context *acontext,
|
||||||
region->pad_mask = region->step - 1;
|
region->pad_mask = region->step - 1;
|
||||||
allocator_count = (region->end - region->start) / region->step;
|
allocator_count = (region->end - region->start) / region->step;
|
||||||
bytes = sizeof(struct fast_allocator_info) * allocator_count;
|
bytes = sizeof(struct fast_allocator_info) * allocator_count;
|
||||||
region->allocators = (struct fast_allocator_info *)malloc(bytes);
|
region->allocators = (struct fast_allocator_info *)fc_malloc(bytes);
|
||||||
if (region->allocators == NULL)
|
if (region->allocators == NULL)
|
||||||
{
|
{
|
||||||
result = errno != 0 ? errno : ENOMEM;
|
return ENOMEM;
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail, errno: %d, error info: %s",
|
|
||||||
__LINE__, bytes, result, STRERROR(result));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
memset(region->allocators, 0, bytes);
|
memset(region->allocators, 0, bytes);
|
||||||
|
|
||||||
|
|
@ -227,14 +218,10 @@ int fast_allocator_init_ex(struct fast_allocator_context *acontext,
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = sizeof(struct fast_region_info) * region_count;
|
bytes = sizeof(struct fast_region_info) * region_count;
|
||||||
acontext->regions = (struct fast_region_info *)malloc(bytes);
|
acontext->regions = (struct fast_region_info *)fc_malloc(bytes);
|
||||||
if (acontext->regions == NULL)
|
if (acontext->regions == NULL)
|
||||||
{
|
{
|
||||||
result = errno != 0 ? errno : ENOMEM;
|
return ENOMEM;
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail, errno: %d, error info: %s",
|
|
||||||
__LINE__, bytes, result, STRERROR(result));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
memcpy(acontext->regions, regions, bytes);
|
memcpy(acontext->regions, regions, bytes);
|
||||||
acontext->region_count = region_count;
|
acontext->region_count = region_count;
|
||||||
|
|
@ -470,7 +457,7 @@ void *fast_allocator_alloc(struct fast_allocator_context *acontext,
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ptr = malloc(alloc_bytes);
|
ptr = fc_malloc(alloc_bytes);
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "shared_func.h"
|
#include "shared_func.h"
|
||||||
|
#include "fc_memory.h"
|
||||||
#include "fast_buffer.h"
|
#include "fast_buffer.h"
|
||||||
|
|
||||||
int fast_buffer_init_ex(FastBuffer *buffer, const int init_capacity)
|
int fast_buffer_init_ex(FastBuffer *buffer, const int init_capacity)
|
||||||
|
|
@ -21,11 +22,9 @@ int fast_buffer_init_ex(FastBuffer *buffer, const int init_capacity)
|
||||||
{
|
{
|
||||||
buffer->alloc_size = 256;
|
buffer->alloc_size = 256;
|
||||||
}
|
}
|
||||||
buffer->data = (char *)malloc(buffer->alloc_size);
|
buffer->data = (char *)fc_malloc(buffer->alloc_size);
|
||||||
if (buffer->data == NULL)
|
if (buffer->data == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail", __LINE__, buffer->alloc_size);
|
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
*(buffer->data) = '\0';
|
*(buffer->data) = '\0';
|
||||||
|
|
@ -68,10 +67,8 @@ int fast_buffer_set_capacity(FastBuffer *buffer, const int capacity)
|
||||||
alloc_size *= 2;
|
alloc_size *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
buff = (char *)malloc(alloc_size);
|
buff = (char *)fc_malloc(alloc_size);
|
||||||
if (buff == NULL) {
|
if (buff == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail", __LINE__, alloc_size);
|
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -222,7 +222,7 @@ int fast_mblock_manager_stat_print_ex(const bool hide_empty, const int order_by)
|
||||||
while (result == EOVERFLOW)
|
while (result == EOVERFLOW)
|
||||||
{
|
{
|
||||||
alloc_size *= 2;
|
alloc_size *= 2;
|
||||||
stats = realloc(stats, sizeof(struct fast_mblock_info) * alloc_size);
|
stats = fc_realloc(stats, sizeof(struct fast_mblock_info) * alloc_size);
|
||||||
if (stats == NULL)
|
if (stats == NULL)
|
||||||
{
|
{
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
@ -435,15 +435,10 @@ static int fast_mblock_prealloc(struct fast_mblock_man *mblock)
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
pNew = (char *)malloc(mblock->info.trunk_size);
|
pNew = (char *)fc_malloc(mblock->info.trunk_size);
|
||||||
if (pNew == NULL)
|
if (pNew == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
return ENOMEM;
|
||||||
"malloc %d bytes fail, " \
|
|
||||||
"errno: %d, error info: %s", \
|
|
||||||
__LINE__, mblock->info.trunk_size,
|
|
||||||
errno, STRERROR(errno));
|
|
||||||
return errno != 0 ? errno : ENOMEM;
|
|
||||||
}
|
}
|
||||||
memset(pNew, 0, mblock->info.trunk_size);
|
memset(pNew, 0, mblock->info.trunk_size);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "common_define.h"
|
#include "common_define.h"
|
||||||
|
#include "fc_memory.h"
|
||||||
#include "chain.h"
|
#include "chain.h"
|
||||||
|
|
||||||
#define FAST_MBLOCK_NAME_SIZE 32
|
#define FAST_MBLOCK_NAME_SIZE 32
|
||||||
|
|
@ -45,6 +46,8 @@ struct fast_mblock_chain {
|
||||||
struct fast_mblock_node *tail;
|
struct fast_mblock_node *tail;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef void (*fc_oom_notify_func)(const int curr_alloc_size);
|
||||||
|
|
||||||
typedef int (*fast_mblock_alloc_init_func)(void *element, void *args);
|
typedef int (*fast_mblock_alloc_init_func)(void *element, void *args);
|
||||||
|
|
||||||
typedef int (*fast_mblock_malloc_trunk_check_func)(
|
typedef int (*fast_mblock_malloc_trunk_check_func)(
|
||||||
|
|
|
||||||
|
|
@ -44,14 +44,10 @@ static int fast_mpool_prealloc(struct fast_mpool_man *mpool,
|
||||||
int bytes;
|
int bytes;
|
||||||
|
|
||||||
bytes = sizeof(struct fast_mpool_malloc) + alloc_size;
|
bytes = sizeof(struct fast_mpool_malloc) + alloc_size;
|
||||||
pMallocNode = (struct fast_mpool_malloc *)malloc(bytes);
|
pMallocNode = (struct fast_mpool_malloc *)fc_malloc(bytes);
|
||||||
if (pMallocNode == NULL)
|
if (pMallocNode == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
return ENOMEM;
|
||||||
"malloc %d bytes fail, " \
|
|
||||||
"errno: %d, error info: %s", \
|
|
||||||
__LINE__, bytes, errno, STRERROR(errno));
|
|
||||||
return errno != 0 ? errno : ENOMEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pMallocNode->alloc_size = alloc_size;
|
pMallocNode->alloc_size = alloc_size;
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,11 @@
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include "fast_task_queue.h"
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "shared_func.h"
|
#include "shared_func.h"
|
||||||
#include "pthread_func.h"
|
#include "pthread_func.h"
|
||||||
|
#include "fc_memory.h"
|
||||||
|
#include "fast_task_queue.h"
|
||||||
|
|
||||||
static struct fast_task_queue g_free_queue;
|
static struct fast_task_queue g_free_queue;
|
||||||
|
|
||||||
|
|
@ -61,26 +62,16 @@ static struct mpool_node *malloc_mpool(const int total_alloc_size)
|
||||||
char *pCharEnd;
|
char *pCharEnd;
|
||||||
struct mpool_node *mpool;
|
struct mpool_node *mpool;
|
||||||
|
|
||||||
mpool = (struct mpool_node *)malloc(sizeof(struct mpool_node));
|
mpool = (struct mpool_node *)fc_malloc(sizeof(struct mpool_node));
|
||||||
if (mpool == NULL)
|
if (mpool == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
|
||||||
"malloc %d bytes fail, " \
|
|
||||||
"errno: %d, error info: %s", \
|
|
||||||
__LINE__, (int)sizeof(struct mpool_node), \
|
|
||||||
errno, STRERROR(errno));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
mpool->next = NULL;
|
mpool->next = NULL;
|
||||||
mpool->blocks = (struct fast_task_info *)malloc(total_alloc_size);
|
mpool->blocks = (struct fast_task_info *)fc_malloc(total_alloc_size);
|
||||||
if (mpool->blocks == NULL)
|
if (mpool->blocks == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
|
||||||
"malloc %d bytes fail, " \
|
|
||||||
"errno: %d, error info: %s", \
|
|
||||||
__LINE__, total_alloc_size, \
|
|
||||||
errno, STRERROR(errno));
|
|
||||||
free(mpool);
|
free(mpool);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -100,15 +91,9 @@ static struct mpool_node *malloc_mpool(const int total_alloc_size)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pTask->data = (char *)malloc(pTask->size);
|
pTask->data = (char *)fc_malloc(pTask->size);
|
||||||
if (pTask->data == NULL)
|
if (pTask->data == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
|
||||||
"malloc %d bytes fail, " \
|
|
||||||
"errno: %d, error info: %s", \
|
|
||||||
__LINE__, pTask->size, \
|
|
||||||
errno, STRERROR(errno));
|
|
||||||
|
|
||||||
free_mpool(mpool, p);
|
free_mpool(mpool, p);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -463,15 +448,10 @@ static int _realloc_buffer(struct fast_task_info *pTask, const int new_size,
|
||||||
const bool copy_data)
|
const bool copy_data)
|
||||||
{
|
{
|
||||||
char *new_buff;
|
char *new_buff;
|
||||||
new_buff = (char *)malloc(new_size);
|
new_buff = (char *)fc_malloc(new_size);
|
||||||
if (new_buff == NULL)
|
if (new_buff == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, "
|
return ENOMEM;
|
||||||
"malloc %d bytes fail, "
|
|
||||||
"errno: %d, error info: %s",
|
|
||||||
__LINE__, new_size,
|
|
||||||
errno, STRERROR(errno));
|
|
||||||
return errno != 0 ? errno : ENOMEM;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "fc_memory.h"
|
||||||
#include "fast_timer.h"
|
#include "fast_timer.h"
|
||||||
|
|
||||||
int fast_timer_init(FastTimer *timer, const int slot_count,
|
int fast_timer_init(FastTimer *timer, const int slot_count,
|
||||||
|
|
@ -18,9 +19,9 @@ int fast_timer_init(FastTimer *timer, const int slot_count,
|
||||||
timer->base_time = current_time; //base time for slot 0
|
timer->base_time = current_time; //base time for slot 0
|
||||||
timer->current_time = current_time;
|
timer->current_time = current_time;
|
||||||
bytes = sizeof(FastTimerSlot) * slot_count;
|
bytes = sizeof(FastTimerSlot) * slot_count;
|
||||||
timer->slots = (FastTimerSlot *)malloc(bytes);
|
timer->slots = (FastTimerSlot *)fc_malloc(bytes);
|
||||||
if (timer->slots == NULL) {
|
if (timer->slots == NULL) {
|
||||||
return errno != 0 ? errno : ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
memset(timer->slots, 0, bytes);
|
memset(timer->slots, 0, bytes);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
//fc_memory.c
|
||||||
|
|
||||||
|
#include "fc_memory.h"
|
||||||
|
|
||||||
|
fc_memory_oom_notify_func g_oom_notify = NULL;
|
||||||
|
|
@ -0,0 +1,97 @@
|
||||||
|
//fc_memory.h
|
||||||
|
|
||||||
|
#ifndef _FC_MEMORY_H
|
||||||
|
#define _FC_MEMORY_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "common_define.h"
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
|
typedef void (*fc_memory_oom_notify_func)(const size_t curr_size);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern fc_memory_oom_notify_func g_oom_notify;
|
||||||
|
|
||||||
|
static inline void *fc_malloc_ex(const char *file,
|
||||||
|
const int line, size_t size)
|
||||||
|
{
|
||||||
|
void *ptr;
|
||||||
|
ptr = malloc(size);
|
||||||
|
if (ptr == NULL) {
|
||||||
|
logError("file: %s, line: %d, malloc %d bytes fail, "
|
||||||
|
"errno: %d, error info: %s", file, line,
|
||||||
|
(int)size, errno, STRERROR(errno));
|
||||||
|
if (g_oom_notify != NULL) {
|
||||||
|
g_oom_notify(size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void *fc_realloc_ex(const char *file,
|
||||||
|
const int line, void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
void *new_ptr;
|
||||||
|
new_ptr = realloc(ptr, size);
|
||||||
|
if (new_ptr == NULL) {
|
||||||
|
logError("file: %s, line: %d, realloc %d bytes fail, "
|
||||||
|
"errno: %d, error info: %s", file, line,
|
||||||
|
(int)size, errno, STRERROR(errno));
|
||||||
|
if (g_oom_notify != NULL) {
|
||||||
|
g_oom_notify(size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline char *fc_strdup_ex(const char *file,
|
||||||
|
const int line, const char *str)
|
||||||
|
{
|
||||||
|
char *output;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = strlen(str);
|
||||||
|
output = (char *)fc_malloc_ex(file, line, len + 1);
|
||||||
|
if (output == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len > 0) {
|
||||||
|
memcpy(output, str, len);
|
||||||
|
}
|
||||||
|
*(output + len) = '\0';
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void *fc_calloc(const char *file,
|
||||||
|
const int line, size_t count, size_t size)
|
||||||
|
{
|
||||||
|
void *ptr;
|
||||||
|
ptr = calloc(count, size);
|
||||||
|
if (ptr == NULL) {
|
||||||
|
logError("file: %s, line: %d, malloc %d bytes fail, "
|
||||||
|
"errno: %d, error info: %s", file, line,
|
||||||
|
(int)(count * size), errno, STRERROR(errno));
|
||||||
|
if (g_oom_notify != NULL) {
|
||||||
|
g_oom_notify(count * size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define fc_malloc(size) fc_malloc_ex(__FILE__, __LINE__, size)
|
||||||
|
#define fc_realloc(ptr, size) fc_realloc_ex(__FILE__, __LINE__, ptr, size)
|
||||||
|
#define fc_calloc(count, size) fc_calloc_ex(__FILE__, __LINE__, count, size)
|
||||||
|
#define fc_strdup(str) fc_strdup_ex(__FILE__, __LINE__, str)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -110,3 +110,37 @@ void *fc_queue_pop_all_ex(struct fc_queue *queue, const bool blocked)
|
||||||
PTHREAD_MUTEX_UNLOCK(&queue->lock);
|
PTHREAD_MUTEX_UNLOCK(&queue->lock);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fc_queue_push_queue_to_head_ex(struct fc_queue *queue,
|
||||||
|
struct fc_queue_info *qinfo, bool *notify)
|
||||||
|
{
|
||||||
|
if (qinfo->head == NULL) {
|
||||||
|
*notify = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PTHREAD_MUTEX_LOCK(&queue->lock);
|
||||||
|
FC_QUEUE_NEXT_PTR(queue, qinfo->tail) = queue->head;
|
||||||
|
queue->head = qinfo->head;
|
||||||
|
if (queue->tail == NULL) {
|
||||||
|
queue->tail = qinfo->tail;
|
||||||
|
*notify = true;
|
||||||
|
} else {
|
||||||
|
*notify = false;
|
||||||
|
}
|
||||||
|
PTHREAD_MUTEX_UNLOCK(&queue->lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fc_queue_pop_to_queue(struct fc_queue *queue,
|
||||||
|
struct fc_queue_info *qinfo)
|
||||||
|
{
|
||||||
|
PTHREAD_MUTEX_LOCK(&queue->lock);
|
||||||
|
if (queue->head != NULL) {
|
||||||
|
qinfo->head = queue->head;
|
||||||
|
qinfo->tail = queue->tail;
|
||||||
|
queue->head = queue->tail = NULL;
|
||||||
|
} else {
|
||||||
|
qinfo->head = qinfo->tail = NULL;
|
||||||
|
}
|
||||||
|
PTHREAD_MUTEX_UNLOCK(&queue->lock);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,12 @@
|
||||||
#include "common_define.h"
|
#include "common_define.h"
|
||||||
#include "fast_mblock.h"
|
#include "fast_mblock.h"
|
||||||
|
|
||||||
|
struct fc_queue_info
|
||||||
|
{
|
||||||
|
void *head;
|
||||||
|
void *tail;
|
||||||
|
};
|
||||||
|
|
||||||
struct fc_queue
|
struct fc_queue
|
||||||
{
|
{
|
||||||
void *head;
|
void *head;
|
||||||
|
|
@ -54,6 +60,20 @@ static inline void fc_queue_push(struct fc_queue *queue, void *data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fc_queue_push_queue_to_head_ex(struct fc_queue *queue,
|
||||||
|
struct fc_queue_info *qinfo, bool *notify);
|
||||||
|
|
||||||
|
static inline void fc_queue_push_queue_to_head(struct fc_queue *queue,
|
||||||
|
struct fc_queue_info *qinfo)
|
||||||
|
{
|
||||||
|
bool notify;
|
||||||
|
|
||||||
|
fc_queue_push_queue_to_head_ex(queue, qinfo, ¬ify);
|
||||||
|
if (notify) {
|
||||||
|
pthread_cond_signal(&(queue->cond));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void *fc_queue_pop_ex(struct fc_queue *queue, const bool blocked);
|
void *fc_queue_pop_ex(struct fc_queue *queue, const bool blocked);
|
||||||
#define fc_queue_pop(queue) fc_queue_pop_ex(queue, true)
|
#define fc_queue_pop(queue) fc_queue_pop_ex(queue, true)
|
||||||
#define fc_queue_try_pop(queue) fc_queue_pop_ex(queue, false)
|
#define fc_queue_try_pop(queue) fc_queue_pop_ex(queue, false)
|
||||||
|
|
@ -62,6 +82,9 @@ void *fc_queue_pop_all_ex(struct fc_queue *queue, const bool blocked);
|
||||||
#define fc_queue_pop_all(queue) fc_queue_pop_all_ex(queue, true)
|
#define fc_queue_pop_all(queue) fc_queue_pop_all_ex(queue, true)
|
||||||
#define fc_queue_try_pop_all(queue) fc_queue_pop_all_ex(queue, false)
|
#define fc_queue_try_pop_all(queue) fc_queue_pop_all_ex(queue, false)
|
||||||
|
|
||||||
|
void fc_queue_pop_to_queue(struct fc_queue *queue,
|
||||||
|
struct fc_queue_info *qinfo);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "fc_memory.h"
|
||||||
#include "flat_skiplist.h"
|
#include "flat_skiplist.h"
|
||||||
|
|
||||||
int flat_skiplist_init_ex(FlatSkiplist *sl, const int level_count,
|
int flat_skiplist_init_ex(FlatSkiplist *sl, const int level_count,
|
||||||
|
|
@ -43,21 +44,15 @@ int flat_skiplist_init_ex(FlatSkiplist *sl, const int level_count,
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = sizeof(FlatSkiplistNode *) * level_count;
|
bytes = sizeof(FlatSkiplistNode *) * level_count;
|
||||||
sl->tmp_previous = (FlatSkiplistNode **)malloc(bytes);
|
sl->tmp_previous = (FlatSkiplistNode **)fc_malloc(bytes);
|
||||||
if (sl->tmp_previous == NULL) {
|
if (sl->tmp_previous == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
return ENOMEM;
|
||||||
"malloc %d bytes fail, errno: %d, error info: %s",
|
|
||||||
__LINE__, bytes, errno, STRERROR(errno));
|
|
||||||
return errno != 0 ? errno : ENOMEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = sizeof(struct fast_mblock_man) * level_count;
|
bytes = sizeof(struct fast_mblock_man) * level_count;
|
||||||
sl->mblocks = (struct fast_mblock_man *)malloc(bytes);
|
sl->mblocks = (struct fast_mblock_man *)fc_malloc(bytes);
|
||||||
if (sl->mblocks == NULL) {
|
if (sl->mblocks == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
return ENOMEM;
|
||||||
"malloc %d bytes fail, errno: %d, error info: %s",
|
|
||||||
__LINE__, bytes, errno, STRERROR(errno));
|
|
||||||
return errno != 0 ? errno : ENOMEM;
|
|
||||||
}
|
}
|
||||||
memset(sl->mblocks, 0, bytes);
|
memset(sl->mblocks, 0, bytes);
|
||||||
|
|
||||||
|
|
|
||||||
11
src/hash.c
11
src/hash.c
|
|
@ -12,6 +12,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include "pthread_func.h"
|
#include "pthread_func.h"
|
||||||
|
#include "fc_memory.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
|
||||||
static unsigned int prime_array[] = {
|
static unsigned int prime_array[] = {
|
||||||
|
|
@ -59,7 +60,7 @@ static int _hash_alloc_buckets(HashArray *pHash, const unsigned int old_capacity
|
||||||
return ENOSPC;
|
return ENOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
pHash->buckets = (HashData **)malloc(bytes);
|
pHash->buckets = (HashData **)fc_malloc(bytes);
|
||||||
if (pHash->buckets == NULL)
|
if (pHash->buckets == NULL)
|
||||||
{
|
{
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
@ -144,7 +145,7 @@ int hash_set_locks(HashArray *pHash, const int lock_count)
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = sizeof(pthread_mutex_t) * lock_count;
|
bytes = sizeof(pthread_mutex_t) * lock_count;
|
||||||
pHash->locks = (pthread_mutex_t *)malloc(bytes);
|
pHash->locks = (pthread_mutex_t *)fc_malloc(bytes);
|
||||||
if (pHash->locks == NULL)
|
if (pHash->locks == NULL)
|
||||||
{
|
{
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
@ -461,7 +462,7 @@ int hash_best_op(HashArray *pHash, const int suggest_capacity)
|
||||||
}
|
}
|
||||||
|
|
||||||
old_capacity = *pHash->capacity;
|
old_capacity = *pHash->capacity;
|
||||||
new_capacity = (unsigned int *)malloc(sizeof(unsigned int));
|
new_capacity = (unsigned int *)fc_malloc(sizeof(unsigned int));
|
||||||
if (new_capacity == NULL)
|
if (new_capacity == NULL)
|
||||||
{
|
{
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
@ -704,7 +705,7 @@ int hash_insert_ex(HashArray *pHash, const void *key, const int key_len, \
|
||||||
return -ENOSPC;
|
return -ENOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
pBuff = (char *)malloc(bytes);
|
pBuff = (char *)fc_malloc(bytes);
|
||||||
if (pBuff == NULL)
|
if (pBuff == NULL)
|
||||||
{
|
{
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
@ -861,7 +862,7 @@ int hash_partial_set(HashArray *pHash, const void *key, const int key_len,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pNewBuff = (char *)malloc(offset + value_len);
|
pNewBuff = (char *)fc_malloc(offset + value_len);
|
||||||
if (pNewBuff == NULL)
|
if (pNewBuff == NULL)
|
||||||
{
|
{
|
||||||
result = errno != 0 ? errno : ENOMEM;
|
result = errno != 0 ? errno : ENOMEM;
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
#include "sockopt.h"
|
#include "sockopt.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "shared_func.h"
|
#include "shared_func.h"
|
||||||
|
#include "fc_memory.h"
|
||||||
#include "http_func.h"
|
#include "http_func.h"
|
||||||
|
|
||||||
int get_url_content_ex(const char *url, const int url_len,
|
int get_url_content_ex(const char *url, const int url_len,
|
||||||
|
|
@ -156,18 +157,11 @@ int get_url_content_ex(const char *url, const int url_len,
|
||||||
|
|
||||||
if (bNeedAlloc)
|
if (bNeedAlloc)
|
||||||
{
|
{
|
||||||
*content = (char *)malloc(alloc_size + 1);
|
*content = (char *)fc_malloc(alloc_size + 1);
|
||||||
if (*content == NULL)
|
if (*content == NULL)
|
||||||
{
|
{
|
||||||
close(sock);
|
close(sock);
|
||||||
result = errno != 0 ? errno : ENOMEM;
|
return ENOMEM;
|
||||||
|
|
||||||
sprintf(error_info, "file: "__FILE__", line: %d, " \
|
|
||||||
"malloc %d bytes fail, errno: %d, " \
|
|
||||||
"error info: %s", __LINE__, alloc_size + 1, \
|
|
||||||
result, STRERROR(result));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -179,20 +173,12 @@ int get_url_content_ex(const char *url, const int url_len,
|
||||||
if (bNeedAlloc)
|
if (bNeedAlloc)
|
||||||
{
|
{
|
||||||
alloc_size *= 2;
|
alloc_size *= 2;
|
||||||
*content = (char *)realloc(*content, alloc_size + 1);
|
*content = (char *)fc_realloc(*content, alloc_size + 1);
|
||||||
if (*content == NULL)
|
if (*content == NULL)
|
||||||
{
|
{
|
||||||
*content_len = 0;
|
*content_len = 0;
|
||||||
close(sock);
|
close(sock);
|
||||||
result = errno != 0 ? errno : ENOMEM;
|
return ENOMEM;
|
||||||
|
|
||||||
sprintf(error_info, "file: "__FILE__", line: %d, " \
|
|
||||||
"realloc %d bytes fail, errno: %d, " \
|
|
||||||
"error info: %s", __LINE__, \
|
|
||||||
alloc_size + 1, \
|
|
||||||
result, STRERROR(result));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
recv_bytes = alloc_size - *content_len;
|
recv_bytes = alloc_size - *content_len;
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
#include "http_func.h"
|
#include "http_func.h"
|
||||||
#include "local_ip_func.h"
|
#include "local_ip_func.h"
|
||||||
#include "pthread_func.h"
|
#include "pthread_func.h"
|
||||||
|
#include "fc_memory.h"
|
||||||
#include "ini_file_reader.h"
|
#include "ini_file_reader.h"
|
||||||
|
|
||||||
#define _LINE_BUFFER_SIZE 512
|
#define _LINE_BUFFER_SIZE 512
|
||||||
|
|
@ -245,11 +246,8 @@ static int iniAnnotationFuncShellExec(IniContext *context,
|
||||||
char *output;
|
char *output;
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
output = (char *)malloc(FAST_INI_ITEM_VALUE_SIZE);
|
output = (char *)fc_malloc(FAST_INI_ITEM_VALUE_SIZE);
|
||||||
if (output == NULL) {
|
if (output == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail",
|
|
||||||
__LINE__, FAST_INI_ITEM_VALUE_LEN + 1);
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -310,11 +308,8 @@ static char *doReplaceVars(IniContext *pContext, const char *param,
|
||||||
int name_len;
|
int name_len;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
output = (char *)malloc(max_size);
|
output = (char *)fc_malloc(max_size);
|
||||||
if (output == NULL) {
|
if (output == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail",
|
|
||||||
__LINE__, FAST_INI_ITEM_VALUE_SIZE);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -493,12 +488,9 @@ int iniSetAnnotationCallBack(AnnotationEntry *annotations, int count)
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = sizeof(AnnotationEntry) * (g_annotation_count + count + 1);
|
bytes = sizeof(AnnotationEntry) * (g_annotation_count + count + 1);
|
||||||
g_annotations = (AnnotationEntry *)realloc(g_annotations, bytes);
|
g_annotations = (AnnotationEntry *)fc_realloc(g_annotations, bytes);
|
||||||
if (g_annotations == NULL)
|
if (g_annotations == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"realloc %d fail, errno: %d, error info: %s",
|
|
||||||
__LINE__, bytes, errno, STRERROR(errno));
|
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -999,13 +991,10 @@ static int iniDoLoadItemsFromBuffer(char *content, IniContext *pContext)
|
||||||
strncasecmp(pLine+1, "include", 7) == 0 && \
|
strncasecmp(pLine+1, "include", 7) == 0 && \
|
||||||
(*(pLine+8) == ' ' || *(pLine+8) == '\t'))
|
(*(pLine+8) == ' ' || *(pLine+8) == '\t'))
|
||||||
{
|
{
|
||||||
pIncludeFilename = strdup(pLine + 9);
|
pIncludeFilename = fc_strdup(pLine + 9);
|
||||||
if (pIncludeFilename == NULL)
|
if (pIncludeFilename == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
result = ENOMEM;
|
||||||
"strdup %d bytes fail", __LINE__, \
|
|
||||||
(int)strlen(pLine + 9) + 1);
|
|
||||||
result = errno != 0 ? errno : ENOMEM;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1127,17 +1116,10 @@ static int iniDoLoadItemsFromBuffer(char *content, IniContext *pContext)
|
||||||
section_name, section_len);
|
section_name, section_len);
|
||||||
if (pSection == NULL)
|
if (pSection == NULL)
|
||||||
{
|
{
|
||||||
pSection = (IniSection *)malloc(sizeof(IniSection));
|
pSection = (IniSection *)fc_malloc(sizeof(IniSection));
|
||||||
if (pSection == NULL)
|
if (pSection == NULL)
|
||||||
{
|
{
|
||||||
result = errno != 0 ? errno : ENOMEM;
|
result = ENOMEM;
|
||||||
logError("file: "__FILE__", line: %d, "\
|
|
||||||
"malloc %d bytes fail, " \
|
|
||||||
"errno: %d, error info: %s", \
|
|
||||||
__LINE__, \
|
|
||||||
(int)sizeof(IniSection), \
|
|
||||||
result, STRERROR(result));
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1361,11 +1343,9 @@ static int checkAllocDynamicContentArray()
|
||||||
alloc = (g_dynamic_content_array.alloc == 0) ? _INIT_DYNAMIC_CONTENTS :
|
alloc = (g_dynamic_content_array.alloc == 0) ? _INIT_DYNAMIC_CONTENTS :
|
||||||
g_dynamic_content_array.alloc * 2;
|
g_dynamic_content_array.alloc * 2;
|
||||||
bytes = sizeof(CDCPair) * alloc;
|
bytes = sizeof(CDCPair) * alloc;
|
||||||
contents = (CDCPair *)malloc(bytes);
|
contents = (CDCPair *)fc_malloc(bytes);
|
||||||
if (contents == NULL)
|
if (contents == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail", __LINE__, bytes);
|
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
memset(contents, 0, bytes);
|
memset(contents, 0, bytes);
|
||||||
|
|
@ -1525,12 +1505,9 @@ static SetDirectiveVars *iniAllocVars(IniContext *pContext, const bool initVars)
|
||||||
|
|
||||||
if (initVars && set->vars == NULL)
|
if (initVars && set->vars == NULL)
|
||||||
{
|
{
|
||||||
set->vars = (HashArray *)malloc(sizeof(HashArray));
|
set->vars = (HashArray *)fc_malloc(sizeof(HashArray));
|
||||||
if (set->vars == NULL)
|
if (set->vars == NULL)
|
||||||
{
|
{
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail",
|
|
||||||
__LINE__, (int)sizeof(HashArray));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (hash_init_ex(set->vars, simple_hash, 17, 0.75, 0, true) != 0)
|
if (hash_init_ex(set->vars, simple_hash, 17, 0.75, 0, true) != 0)
|
||||||
|
|
@ -1645,11 +1622,9 @@ static char *iniAllocContent(IniContext *pContext, const int content_len)
|
||||||
alloc = pDynamicContents->alloc * 2;
|
alloc = pDynamicContents->alloc * 2;
|
||||||
}
|
}
|
||||||
bytes = sizeof(char *) * alloc;
|
bytes = sizeof(char *) * alloc;
|
||||||
contents = (char **)malloc(bytes);
|
contents = (char **)fc_malloc(bytes);
|
||||||
if (contents == NULL)
|
if (contents == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail", __LINE__, bytes);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memset(contents, 0, bytes);
|
memset(contents, 0, bytes);
|
||||||
|
|
@ -1663,11 +1638,9 @@ static char *iniAllocContent(IniContext *pContext, const int content_len)
|
||||||
pDynamicContents->alloc = alloc;
|
pDynamicContents->alloc = alloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
buff = malloc(content_len);
|
buff = fc_malloc(content_len);
|
||||||
if (buff == NULL)
|
if (buff == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail", __LINE__, content_len);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pDynamicContents->contents[pDynamicContents->count++] = buff;
|
pDynamicContents->contents[pDynamicContents->count++] = buff;
|
||||||
|
|
@ -1700,11 +1673,9 @@ static int iniCheckAllocAnnotations(DynamicAnnotations *pDynamicAnnotations,
|
||||||
alloc *= 2;
|
alloc *= 2;
|
||||||
}
|
}
|
||||||
bytes = sizeof(AnnotationEntry) * alloc;
|
bytes = sizeof(AnnotationEntry) * alloc;
|
||||||
annotations = (AnnotationEntry *)malloc(bytes);
|
annotations = (AnnotationEntry *)fc_malloc(bytes);
|
||||||
if (annotations == NULL)
|
if (annotations == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail", __LINE__, bytes);
|
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
memset(annotations, 0, bytes);
|
memset(annotations, 0, bytes);
|
||||||
|
|
@ -2149,10 +2120,8 @@ static int iniDoProccessSet(char *pSet, char **ppSetEnd,
|
||||||
if (new_value != value) {
|
if (new_value != value) {
|
||||||
free(new_value);
|
free(new_value);
|
||||||
}
|
}
|
||||||
new_value = strdup(output);
|
new_value = fc_strdup(output);
|
||||||
if (new_value == NULL) {
|
if (new_value == NULL) {
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail", __LINE__, value_len + 1);
|
|
||||||
new_value = value;
|
new_value = value;
|
||||||
value_len = 0;
|
value_len = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -2718,7 +2687,6 @@ static int iniLoadItemsFromBuffer(char *content, IniContext *pContext)
|
||||||
static int remallocSection(IniSection *pSection, IniItem **pItem)
|
static int remallocSection(IniSection *pSection, IniItem **pItem)
|
||||||
{
|
{
|
||||||
int bytes;
|
int bytes;
|
||||||
int result;
|
|
||||||
int alloc;
|
int alloc;
|
||||||
IniItem *pNew;
|
IniItem *pNew;
|
||||||
|
|
||||||
|
|
@ -2731,13 +2699,10 @@ static int remallocSection(IniSection *pSection, IniItem **pItem)
|
||||||
alloc = pSection->alloc * 2;
|
alloc = pSection->alloc * 2;
|
||||||
}
|
}
|
||||||
bytes = sizeof(IniItem) * alloc;
|
bytes = sizeof(IniItem) * alloc;
|
||||||
pNew = (IniItem *)malloc(bytes);
|
pNew = (IniItem *)fc_malloc(bytes);
|
||||||
if (pNew == NULL)
|
if (pNew == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
return ENOMEM;
|
||||||
"malloc %d bytes fail", __LINE__, bytes);
|
|
||||||
result = errno != 0 ? errno : ENOMEM;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSection->count > 0)
|
if (pSection->count > 0)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include "fc_memory.h"
|
||||||
#include "ioevent.h"
|
#include "ioevent.h"
|
||||||
|
|
||||||
#if IOEVENT_USE_KQUEUE
|
#if IOEVENT_USE_KQUEUE
|
||||||
|
|
@ -45,21 +46,21 @@ int ioevent_init(IOEventPoller *ioevent, const int size,
|
||||||
return errno != 0 ? errno : ENOMEM;
|
return errno != 0 ? errno : ENOMEM;
|
||||||
}
|
}
|
||||||
bytes = sizeof(struct epoll_event) * size;
|
bytes = sizeof(struct epoll_event) * size;
|
||||||
ioevent->events = (struct epoll_event *)malloc(bytes);
|
ioevent->events = (struct epoll_event *)fc_malloc(bytes);
|
||||||
#elif IOEVENT_USE_KQUEUE
|
#elif IOEVENT_USE_KQUEUE
|
||||||
ioevent->poll_fd = kqueue();
|
ioevent->poll_fd = kqueue();
|
||||||
if (ioevent->poll_fd < 0) {
|
if (ioevent->poll_fd < 0) {
|
||||||
return errno != 0 ? errno : ENOMEM;
|
return errno != 0 ? errno : ENOMEM;
|
||||||
}
|
}
|
||||||
bytes = sizeof(struct kevent) * size;
|
bytes = sizeof(struct kevent) * size;
|
||||||
ioevent->events = (struct kevent *)malloc(bytes);
|
ioevent->events = (struct kevent *)fc_malloc(bytes);
|
||||||
#elif IOEVENT_USE_PORT
|
#elif IOEVENT_USE_PORT
|
||||||
ioevent->poll_fd = port_create();
|
ioevent->poll_fd = port_create();
|
||||||
if (ioevent->poll_fd < 0) {
|
if (ioevent->poll_fd < 0) {
|
||||||
return errno != 0 ? errno : ENOMEM;
|
return errno != 0 ? errno : ENOMEM;
|
||||||
}
|
}
|
||||||
bytes = sizeof(port_event_t) * size;
|
bytes = sizeof(port_event_t) * size;
|
||||||
ioevent->events = (port_event_t *)malloc(bytes);
|
ioevent->events = (port_event_t *)fc_malloc(bytes);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ioevent->events == NULL) {
|
if (ioevent->events == NULL) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "shared_func.h"
|
#include "shared_func.h"
|
||||||
|
#include "fc_memory.h"
|
||||||
#include "json_parser.h"
|
#include "json_parser.h"
|
||||||
|
|
||||||
#define EXPECT_STR_LEN 80
|
#define EXPECT_STR_LEN 80
|
||||||
|
|
@ -63,7 +64,7 @@ static int json_escape_string(const string_t *input, string_t *output,
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
size = 2 * input->len + 1;
|
size = 2 * input->len + 1;
|
||||||
output->str = (char *)malloc(size);
|
output->str = (char *)fc_malloc(size);
|
||||||
if (output->str == NULL) {
|
if (output->str == NULL) {
|
||||||
snprintf(error_info, error_size, "malloc %d bytes fail", size);
|
snprintf(error_info, error_size, "malloc %d bytes fail", size);
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
@ -201,9 +202,9 @@ static int check_alloc_array(common_array_t *array,
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = array->element_size * array->alloc;
|
bytes = array->element_size * array->alloc;
|
||||||
array->elements = realloc(array->elements, bytes);
|
array->elements = fc_realloc(array->elements, bytes);
|
||||||
if (array->elements == NULL) {
|
if (array->elements == NULL) {
|
||||||
snprintf(error_info, error_size, "malloc %d bytes fail", bytes);
|
snprintf(error_info, error_size, "realloc %d bytes fail", bytes);
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -249,7 +250,7 @@ static int prepare_json_parse(const string_t *input, common_array_t *array,
|
||||||
}
|
}
|
||||||
|
|
||||||
buff_len = input->len - 2;
|
buff_len = input->len - 2;
|
||||||
array->buff = (char *)malloc(buff_len + 1);
|
array->buff = (char *)fc_malloc(buff_len + 1);
|
||||||
if (array->buff == NULL) {
|
if (array->buff == NULL) {
|
||||||
snprintf(error_info, error_size,
|
snprintf(error_info, error_size,
|
||||||
"malloc %d bytes fail", buff_len + 1);
|
"malloc %d bytes fail", buff_len + 1);
|
||||||
|
|
@ -384,7 +385,7 @@ int encode_json_array(json_array_t *array, string_t *output,
|
||||||
size += 2 * el->len + 3;
|
size += 2 * el->len + 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
output->str = (char *)malloc(size);
|
output->str = (char *)fc_malloc(size);
|
||||||
if (output->str == NULL) {
|
if (output->str == NULL) {
|
||||||
snprintf(error_info, error_size, "malloc %d bytes fail", size);
|
snprintf(error_info, error_size, "malloc %d bytes fail", size);
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
@ -511,7 +512,7 @@ int encode_json_map(json_map_t *map, string_t *output,
|
||||||
size += 2 * (pair->key.len + pair->value.len + 2) + 1;
|
size += 2 * (pair->key.len + pair->value.len + 2) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
output->str = (char *)malloc(size);
|
output->str = (char *)fc_malloc(size);
|
||||||
if (output->str == NULL) {
|
if (output->str == NULL) {
|
||||||
snprintf(error_info, error_size, "malloc %d bytes fail", size);
|
snprintf(error_info, error_size, "malloc %d bytes fail", size);
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "fc_memory.h"
|
||||||
#include "multi_skiplist.h"
|
#include "multi_skiplist.h"
|
||||||
|
|
||||||
int multi_skiplist_init_ex(MultiSkiplist *sl, const int level_count,
|
int multi_skiplist_init_ex(MultiSkiplist *sl, const int level_count,
|
||||||
|
|
@ -44,21 +45,15 @@ int multi_skiplist_init_ex(MultiSkiplist *sl, const int level_count,
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = sizeof(MultiSkiplistNode *) * level_count;
|
bytes = sizeof(MultiSkiplistNode *) * level_count;
|
||||||
sl->tmp_previous = (MultiSkiplistNode **)malloc(bytes);
|
sl->tmp_previous = (MultiSkiplistNode **)fc_malloc(bytes);
|
||||||
if (sl->tmp_previous == NULL) {
|
if (sl->tmp_previous == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
return ENOMEM;
|
||||||
"malloc %d bytes fail, errno: %d, error info: %s",
|
|
||||||
__LINE__, bytes, errno, STRERROR(errno));
|
|
||||||
return errno != 0 ? errno : ENOMEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = sizeof(struct fast_mblock_man) * level_count;
|
bytes = sizeof(struct fast_mblock_man) * level_count;
|
||||||
sl->mblocks = (struct fast_mblock_man *)malloc(bytes);
|
sl->mblocks = (struct fast_mblock_man *)fc_malloc(bytes);
|
||||||
if (sl->mblocks == NULL) {
|
if (sl->mblocks == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
return ENOMEM;
|
||||||
"malloc %d bytes fail, errno: %d, error info: %s",
|
|
||||||
__LINE__, bytes, errno, STRERROR(errno));
|
|
||||||
return errno != 0 ? errno : ENOMEM;
|
|
||||||
}
|
}
|
||||||
memset(sl->mblocks, 0, bytes);
|
memset(sl->mblocks, 0, bytes);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,9 @@
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include "pthread_func.h"
|
#include "fc_memory.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "pthread_func.h"
|
||||||
|
|
||||||
int init_pthread_lock(pthread_mutex_t *pthread_lock)
|
int init_pthread_lock(pthread_mutex_t *pthread_lock)
|
||||||
{
|
{
|
||||||
|
|
@ -147,10 +148,8 @@ int create_work_threads(int *count, void *(*start_func)(void *),
|
||||||
} else {
|
} else {
|
||||||
int bytes;
|
int bytes;
|
||||||
bytes = sizeof(pthread_t) * *count;
|
bytes = sizeof(pthread_t) * *count;
|
||||||
the_tids = (pthread_t *)malloc(bytes);
|
the_tids = (pthread_t *)fc_malloc(bytes);
|
||||||
if (the_tids == NULL) {
|
if (the_tids == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail", __LINE__, bytes);
|
|
||||||
pthread_attr_destroy(&thread_attr);
|
pthread_attr_destroy(&thread_attr);
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
@ -200,10 +199,8 @@ int create_work_threads_ex(int *count, void *(*start_func)(void *),
|
||||||
} else {
|
} else {
|
||||||
int bytes;
|
int bytes;
|
||||||
bytes = sizeof(void *) * (*count);
|
bytes = sizeof(void *) * (*count);
|
||||||
pp_args = (void **)malloc(bytes);
|
pp_args = (void **)fc_malloc(bytes);
|
||||||
if (pp_args == NULL) {
|
if (pp_args == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail", __LINE__, bytes);
|
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
#include "shared_func.h"
|
#include "shared_func.h"
|
||||||
#include "pthread_func.h"
|
#include "pthread_func.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "fc_memory.h"
|
||||||
#include "sched_thread.h"
|
#include "sched_thread.h"
|
||||||
|
|
||||||
volatile bool g_schedule_flag = false;
|
volatile bool g_schedule_flag = false;
|
||||||
|
|
@ -232,7 +233,6 @@ static int do_check_waiting(ScheduleContext *pContext)
|
||||||
ScheduleEntry *pSchedEnd;
|
ScheduleEntry *pSchedEnd;
|
||||||
int allocCount;
|
int allocCount;
|
||||||
int newCount;
|
int newCount;
|
||||||
int result;
|
|
||||||
int deleteCount;
|
int deleteCount;
|
||||||
|
|
||||||
pScheduleArray = &(pContext->scheduleArray);
|
pScheduleArray = &(pContext->scheduleArray);
|
||||||
|
|
@ -283,21 +283,14 @@ static int do_check_waiting(ScheduleContext *pContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
allocCount = pScheduleArray->count + waiting_schedule_array.count;
|
allocCount = pScheduleArray->count + waiting_schedule_array.count;
|
||||||
newEntries = (ScheduleEntry *)malloc(sizeof(ScheduleEntry) * allocCount);
|
newEntries = (ScheduleEntry *)fc_malloc(sizeof(ScheduleEntry) * allocCount);
|
||||||
if (newEntries == NULL)
|
if (newEntries == NULL)
|
||||||
{
|
{
|
||||||
result = errno != 0 ? errno : ENOMEM;
|
|
||||||
logError("file: "__FILE__", line: %d, " \
|
|
||||||
"malloc %d bytes failed, " \
|
|
||||||
"errno: %d, error info: %s", \
|
|
||||||
__LINE__, (int)sizeof(ScheduleEntry) * allocCount, \
|
|
||||||
result, STRERROR(result));
|
|
||||||
|
|
||||||
if (deleteCount > 0)
|
if (deleteCount > 0)
|
||||||
{
|
{
|
||||||
sched_make_chain(pContext);
|
sched_make_chain(pContext);
|
||||||
}
|
}
|
||||||
return result;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pScheduleArray->count > 0)
|
if (pScheduleArray->count > 0)
|
||||||
|
|
@ -546,7 +539,6 @@ static void *sched_thread_entrance(void *args)
|
||||||
static int sched_dup_array(const ScheduleArray *pSrcArray, \
|
static int sched_dup_array(const ScheduleArray *pSrcArray, \
|
||||||
ScheduleArray *pDestArray)
|
ScheduleArray *pDestArray)
|
||||||
{
|
{
|
||||||
int result;
|
|
||||||
int bytes;
|
int bytes;
|
||||||
|
|
||||||
if (pSrcArray->count == 0)
|
if (pSrcArray->count == 0)
|
||||||
|
|
@ -557,15 +549,10 @@ static int sched_dup_array(const ScheduleArray *pSrcArray, \
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = sizeof(ScheduleEntry) * pSrcArray->count;
|
bytes = sizeof(ScheduleEntry) * pSrcArray->count;
|
||||||
pDestArray->entries = (ScheduleEntry *)malloc(bytes);
|
pDestArray->entries = (ScheduleEntry *)fc_malloc(bytes);
|
||||||
if (pDestArray->entries == NULL)
|
if (pDestArray->entries == NULL)
|
||||||
{
|
{
|
||||||
result = errno != 0 ? errno : ENOMEM;
|
return ENOMEM;
|
||||||
logError("file: "__FILE__", line: %d, " \
|
|
||||||
"malloc %d bytes failed, " \
|
|
||||||
"errno: %d, error info: %s", \
|
|
||||||
__LINE__, bytes, result, STRERROR(result));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pDestArray->entries, pSrcArray->entries, bytes);
|
memcpy(pDestArray->entries, pSrcArray->entries, bytes);
|
||||||
|
|
@ -587,15 +574,10 @@ static int sched_append_array(const ScheduleArray *pSrcArray, \
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = sizeof(ScheduleEntry) * (pDestArray->count + pSrcArray->count);
|
bytes = sizeof(ScheduleEntry) * (pDestArray->count + pSrcArray->count);
|
||||||
new_entries = (ScheduleEntry *)malloc(bytes);
|
new_entries = (ScheduleEntry *)fc_malloc(bytes);
|
||||||
if (new_entries == NULL)
|
if (new_entries == NULL)
|
||||||
{
|
{
|
||||||
result = errno != 0 ? errno : ENOMEM;
|
return ENOMEM;
|
||||||
logError("file: "__FILE__", line: %d, " \
|
|
||||||
"malloc %d bytes failed, " \
|
|
||||||
"errno: %d, error info: %s", \
|
|
||||||
__LINE__, bytes, result, STRERROR(result));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pDestArray->entries != NULL)
|
if (pDestArray->entries != NULL)
|
||||||
|
|
@ -681,16 +663,10 @@ int sched_start_ex(ScheduleArray *pScheduleArray, pthread_t *ptid,
|
||||||
pthread_attr_t thread_attr;
|
pthread_attr_t thread_attr;
|
||||||
ScheduleContext *pContext;
|
ScheduleContext *pContext;
|
||||||
|
|
||||||
pContext = (ScheduleContext *)malloc(sizeof(ScheduleContext));
|
pContext = (ScheduleContext *)fc_malloc(sizeof(ScheduleContext));
|
||||||
if (pContext == NULL)
|
if (pContext == NULL)
|
||||||
{
|
{
|
||||||
result = errno != 0 ? errno : ENOMEM;
|
return ENOMEM;
|
||||||
logError("file: "__FILE__", line: %d, " \
|
|
||||||
"malloc %d bytes failed, " \
|
|
||||||
"errno: %d, error info: %s", \
|
|
||||||
__LINE__, (int)sizeof(ScheduleContext), \
|
|
||||||
result, STRERROR(result));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
memset(pContext, 0, sizeof(ScheduleContext));
|
memset(pContext, 0, sizeof(ScheduleContext));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -119,10 +119,8 @@ static int fc_server_check_alloc_group_addresses(FCAddressPtrArray *array)
|
||||||
|
|
||||||
new_alloc = array->alloc > 0 ? 2 * array->alloc : 2;
|
new_alloc = array->alloc > 0 ? 2 * array->alloc : 2;
|
||||||
bytes = sizeof(FCAddressInfo *) * new_alloc;
|
bytes = sizeof(FCAddressInfo *) * new_alloc;
|
||||||
new_addrs = (FCAddressInfo **)malloc(bytes);
|
new_addrs = (FCAddressInfo **)fc_malloc(bytes);
|
||||||
if (new_addrs == NULL) {
|
if (new_addrs == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail", __LINE__, bytes);
|
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
memset(new_addrs, 0, bytes);
|
memset(new_addrs, 0, bytes);
|
||||||
|
|
@ -154,11 +152,8 @@ static FCAddressInfo *fc_server_add_to_uniq_addresses(
|
||||||
if (fc_server_check_alloc_group_addresses(addr_ptr_array) != 0) {
|
if (fc_server_check_alloc_group_addresses(addr_ptr_array) != 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
p = (FCAddressInfo *)malloc(sizeof(FCAddressInfo));
|
p = (FCAddressInfo *)fc_malloc(sizeof(FCAddressInfo));
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail", __LINE__,
|
|
||||||
(int)sizeof(FCAddressInfo));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,7 +164,6 @@ static FCAddressInfo *fc_server_add_to_uniq_addresses(
|
||||||
|
|
||||||
static int fc_server_init_ip_port_array(FCServerConfig *ctx)
|
static int fc_server_init_ip_port_array(FCServerConfig *ctx)
|
||||||
{
|
{
|
||||||
int result;
|
|
||||||
int count;
|
int count;
|
||||||
int bytes;
|
int bytes;
|
||||||
FCServerMapArray *map_array;
|
FCServerMapArray *map_array;
|
||||||
|
|
@ -183,14 +177,9 @@ static int fc_server_init_ip_port_array(FCServerConfig *ctx)
|
||||||
|
|
||||||
count = fc_server_calc_ip_port_count(ctx);
|
count = fc_server_calc_ip_port_count(ctx);
|
||||||
bytes = sizeof(FCServerMap) * count;
|
bytes = sizeof(FCServerMap) * count;
|
||||||
map_array->maps = (FCServerMap *)malloc(bytes);
|
map_array->maps = (FCServerMap *)fc_malloc(bytes);
|
||||||
if (map_array->maps == NULL) {
|
if (map_array->maps == NULL) {
|
||||||
result = errno != 0 ? errno : ENOMEM;
|
return ENOMEM;
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail, "
|
|
||||||
"errno: %d, error info: %s", __LINE__,
|
|
||||||
bytes, result, STRERROR(result));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
memset(map_array->maps, 0, bytes);
|
memset(map_array->maps, 0, bytes);
|
||||||
|
|
||||||
|
|
@ -471,10 +460,8 @@ static int fc_server_alloc_servers(FCServerInfoArray *array,
|
||||||
int bytes;
|
int bytes;
|
||||||
|
|
||||||
bytes = sizeof(FCServerInfo) * target_count;
|
bytes = sizeof(FCServerInfo) * target_count;
|
||||||
array->servers = (FCServerInfo *)malloc(bytes);
|
array->servers = (FCServerInfo *)fc_malloc(bytes);
|
||||||
if (array->servers == NULL) {
|
if (array->servers == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail", __LINE__, bytes);
|
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
memset(array->servers, 0, bytes);
|
memset(array->servers, 0, bytes);
|
||||||
|
|
@ -495,10 +482,8 @@ static int fc_server_check_alloc_group_address_ptrs(FCAddressPtrArray *array)
|
||||||
|
|
||||||
new_alloc = array->alloc > 0 ? 2 * array->alloc : 1;
|
new_alloc = array->alloc > 0 ? 2 * array->alloc : 1;
|
||||||
bytes = sizeof(FCAddressInfo *) * new_alloc;
|
bytes = sizeof(FCAddressInfo *) * new_alloc;
|
||||||
new_addrs = (FCAddressInfo **)malloc(bytes);
|
new_addrs = (FCAddressInfo **)fc_malloc(bytes);
|
||||||
if (new_addrs == NULL) {
|
if (new_addrs == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail", __LINE__, bytes);
|
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
memset(new_addrs, 0, bytes);
|
memset(new_addrs, 0, bytes);
|
||||||
|
|
@ -1104,10 +1089,8 @@ static int fc_server_load_servers(FCServerConfig *ctx,
|
||||||
sections = fixed;
|
sections = fixed;
|
||||||
} else {
|
} else {
|
||||||
alloc_bytes = sizeof(IniSectionInfo) * count;
|
alloc_bytes = sizeof(IniSectionInfo) * count;
|
||||||
sections = (IniSectionInfo *)malloc(alloc_bytes);
|
sections = (IniSectionInfo *)fc_malloc(alloc_bytes);
|
||||||
if (sections == NULL) {
|
if (sections == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail", __LINE__, alloc_bytes);
|
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,10 @@
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "shared_func.h"
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "sockopt.h"
|
#include "sockopt.h"
|
||||||
|
#include "fc_memory.h"
|
||||||
|
#include "shared_func.h"
|
||||||
|
|
||||||
#ifdef OS_LINUX
|
#ifdef OS_LINUX
|
||||||
#include <sys/sysinfo.h>
|
#include <sys/sysinfo.h>
|
||||||
|
|
@ -295,12 +296,9 @@ int getUserProcIds(const char *progName, const bool bAllOwners, \
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pTargetProg = (char *)malloc(strlen(progName) + 1);
|
pTargetProg = (char *)fc_malloc(strlen(progName) + 1);
|
||||||
if (pTargetProg == NULL)
|
if (pTargetProg == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
|
||||||
"malloc %d bytes fail", __LINE__, \
|
|
||||||
(int)strlen(progName) + 1);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -704,11 +702,8 @@ int fc_get_file_line_count_ex(const char *filename,
|
||||||
char *buff;
|
char *buff;
|
||||||
|
|
||||||
*line_count = 0;
|
*line_count = 0;
|
||||||
buff = (char *)malloc(READ_BUFFER_SIZE);
|
buff = (char *)fc_malloc(READ_BUFFER_SIZE);
|
||||||
if (buff == NULL) {
|
if (buff == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail",
|
|
||||||
__LINE__, READ_BUFFER_SIZE);
|
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -779,12 +774,9 @@ char **split(char *src, const char seperator, const int nMaxCols, int *nColCount
|
||||||
*nColCount = nMaxCols;
|
*nColCount = nMaxCols;
|
||||||
}
|
}
|
||||||
|
|
||||||
pCurrent = pCols = (char **)malloc(sizeof(char *) * (*nColCount));
|
pCurrent = pCols = (char **)fc_malloc(sizeof(char *) * (*nColCount));
|
||||||
if (pCols == NULL)
|
if (pCols == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
|
||||||
"malloc %d bytes fail", __LINE__, \
|
|
||||||
(int)sizeof(char *) * (*nColCount));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1202,16 +1194,13 @@ int getFileContent(const char *filename, char **buff, int64_t *file_size)
|
||||||
return errno != 0 ? errno : EIO;
|
return errno != 0 ? errno : EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
*buff = (char *)malloc(*file_size + 1);
|
*buff = (char *)fc_malloc(*file_size + 1);
|
||||||
if (*buff == NULL)
|
if (*buff == NULL)
|
||||||
{
|
{
|
||||||
*file_size = 0;
|
*file_size = 0;
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
logError("file: "__FILE__", line: %d, " \
|
return ENOMEM;
|
||||||
"malloc %d bytes fail", __LINE__, \
|
|
||||||
(int)(*file_size + 1));
|
|
||||||
return errno != 0 ? errno : ENOMEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lseek(fd, 0, SEEK_SET) < 0)
|
if (lseek(fd, 0, SEEK_SET) < 0)
|
||||||
|
|
@ -1765,15 +1754,10 @@ static int check_realloc_allow_ips(in_addr_t **allow_ip_addrs,
|
||||||
{
|
{
|
||||||
*alloc_count = target_ip_count;
|
*alloc_count = target_ip_count;
|
||||||
bytes = sizeof(in_addr_t) * (*alloc_count);
|
bytes = sizeof(in_addr_t) * (*alloc_count);
|
||||||
*allow_ip_addrs = (in_addr_t *)realloc(*allow_ip_addrs, bytes);
|
*allow_ip_addrs = (in_addr_t *)fc_realloc(*allow_ip_addrs, bytes);
|
||||||
if (*allow_ip_addrs == NULL)
|
if (*allow_ip_addrs == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, "\
|
return ENOMEM;
|
||||||
"malloc %d bytes fail, " \
|
|
||||||
"errno: %d, error info: %s", \
|
|
||||||
__LINE__, bytes, errno, STRERROR(errno));
|
|
||||||
|
|
||||||
return errno != 0 ? errno : ENOMEM;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2062,14 +2046,10 @@ int load_allow_hosts(IniContext *pIniContext, \
|
||||||
|
|
||||||
alloc_count = count;
|
alloc_count = count;
|
||||||
*allow_ip_count = 0;
|
*allow_ip_count = 0;
|
||||||
*allow_ip_addrs = (in_addr_t *)malloc(sizeof(in_addr_t) * alloc_count);
|
*allow_ip_addrs = (in_addr_t *)fc_malloc(sizeof(in_addr_t) * alloc_count);
|
||||||
if (*allow_ip_addrs == NULL)
|
if (*allow_ip_addrs == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
return ENOMEM;
|
||||||
"malloc %d bytes fail, errno: %d, error info: %s.", \
|
|
||||||
__LINE__, (int)sizeof(in_addr_t) * alloc_count, \
|
|
||||||
errno, STRERROR(errno));
|
|
||||||
return errno != 0 ? errno : ENOMEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (pItem=pItemStart; pItem<pItemEnd; pItem++)
|
for (pItem=pItemStart; pItem<pItemEnd; pItem++)
|
||||||
|
|
@ -2397,16 +2377,11 @@ int buffer_strcpy(BufferInfo *pBuff, const char *str)
|
||||||
}
|
}
|
||||||
|
|
||||||
pBuff->alloc_size = pBuff->length + 1;
|
pBuff->alloc_size = pBuff->length + 1;
|
||||||
pBuff->buff = (char *)malloc(pBuff->alloc_size);
|
pBuff->buff = (char *)fc_malloc(pBuff->alloc_size);
|
||||||
if (pBuff->buff == NULL)
|
if (pBuff->buff == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
|
||||||
"malloc %d bytes fail, " \
|
|
||||||
"errno: %d, error info: %s", \
|
|
||||||
__LINE__, pBuff->alloc_size, \
|
|
||||||
errno, STRERROR(errno));
|
|
||||||
pBuff->alloc_size = 0;
|
pBuff->alloc_size = 0;
|
||||||
return errno != 0 ? errno : ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2425,16 +2400,11 @@ int buffer_memcpy(BufferInfo *pBuff, const char *buff, const int len)
|
||||||
}
|
}
|
||||||
|
|
||||||
pBuff->alloc_size = pBuff->length;
|
pBuff->alloc_size = pBuff->length;
|
||||||
pBuff->buff = (char *)malloc(pBuff->alloc_size);
|
pBuff->buff = (char *)fc_malloc(pBuff->alloc_size);
|
||||||
if (pBuff->buff == NULL)
|
if (pBuff->buff == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
|
||||||
"malloc %d bytes fail, " \
|
|
||||||
"errno: %d, error info: %s", \
|
|
||||||
__LINE__, pBuff->alloc_size, \
|
|
||||||
errno, STRERROR(errno));
|
|
||||||
pBuff->alloc_size = 0;
|
pBuff->alloc_size = 0;
|
||||||
return errno != 0 ? errno : ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2876,15 +2846,12 @@ bool ends_with(const char *str, const char *needle)
|
||||||
return memcmp(str + start_offset, needle, needle_len) == 0;
|
return memcmp(str + start_offset, needle, needle_len) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *fc_strdup(const char *str, const int len)
|
char *fc_strdup1(const char *str, const int len)
|
||||||
{
|
{
|
||||||
char *output;
|
char *output;
|
||||||
|
|
||||||
output = (char *)malloc(len + 1);
|
output = (char *)fc_malloc(len + 1);
|
||||||
if (output == NULL) {
|
if (output == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail",
|
|
||||||
__LINE__, len + 1);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3081,11 +3048,9 @@ int fc_ceil_prime(const int n)
|
||||||
|
|
||||||
int fc_init_buffer(BufferInfo *buffer, const int buffer_size)
|
int fc_init_buffer(BufferInfo *buffer, const int buffer_size)
|
||||||
{
|
{
|
||||||
buffer->buff = (char *)malloc(buffer_size);
|
buffer->buff = (char *)fc_malloc(buffer_size);
|
||||||
if (buffer->buff == NULL)
|
if (buffer->buff == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail", __LINE__, buffer_size);
|
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
buffer->alloc_size = buffer_size;
|
buffer->alloc_size = buffer_size;
|
||||||
|
|
|
||||||
|
|
@ -855,13 +855,13 @@ bool starts_with(const char *str, const char *needle);
|
||||||
*/
|
*/
|
||||||
bool ends_with(const char *str, const char *needle);
|
bool ends_with(const char *str, const char *needle);
|
||||||
|
|
||||||
/** strdup
|
/** strdup extension
|
||||||
* parameters:
|
* parameters:
|
||||||
* str: the string to duplicate
|
* str: the string to duplicate
|
||||||
* len: the length of string
|
* len: the length of string
|
||||||
* return: the duplicated string, NULL for fail
|
* return: the duplicated string, NULL for fail
|
||||||
*/
|
*/
|
||||||
char *fc_strdup(const char *str, const int len);
|
char *fc_strdup1(const char *str, const int len);
|
||||||
|
|
||||||
/** memmem
|
/** memmem
|
||||||
* parameters:
|
* parameters:
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "fc_memory.h"
|
||||||
#include "skiplist_set.h"
|
#include "skiplist_set.h"
|
||||||
|
|
||||||
int skiplist_set_init_ex(SkiplistSet *sl, const int level_count,
|
int skiplist_set_init_ex(SkiplistSet *sl, const int level_count,
|
||||||
|
|
@ -43,21 +44,15 @@ int skiplist_set_init_ex(SkiplistSet *sl, const int level_count,
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = sizeof(SkiplistSetNode *) * level_count;
|
bytes = sizeof(SkiplistSetNode *) * level_count;
|
||||||
sl->tmp_previous = (SkiplistSetNode **)malloc(bytes);
|
sl->tmp_previous = (SkiplistSetNode **)fc_malloc(bytes);
|
||||||
if (sl->tmp_previous == NULL) {
|
if (sl->tmp_previous == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
return ENOMEM;
|
||||||
"malloc %d bytes fail, errno: %d, error info: %s",
|
|
||||||
__LINE__, bytes, errno, STRERROR(errno));
|
|
||||||
return errno != 0 ? errno : ENOMEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = sizeof(struct fast_mblock_man) * level_count;
|
bytes = sizeof(struct fast_mblock_man) * level_count;
|
||||||
sl->mblocks = (struct fast_mblock_man *)malloc(bytes);
|
sl->mblocks = (struct fast_mblock_man *)fc_malloc(bytes);
|
||||||
if (sl->mblocks == NULL) {
|
if (sl->mblocks == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
return ENOMEM;
|
||||||
"malloc %d bytes fail, errno: %d, error info: %s",
|
|
||||||
__LINE__, bytes, errno, STRERROR(errno));
|
|
||||||
return errno != 0 ? errno : ENOMEM;
|
|
||||||
}
|
}
|
||||||
memset(sl->mblocks, 0, bytes);
|
memset(sl->mblocks, 0, bytes);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "shared_func.h"
|
#include "shared_func.h"
|
||||||
|
#include "fc_memory.h"
|
||||||
#include "system_info.h"
|
#include "system_info.h"
|
||||||
|
|
||||||
#ifdef OS_LINUX
|
#ifdef OS_LINUX
|
||||||
|
|
@ -327,11 +328,9 @@ static int check_process_capacity(FastProcessArray *proc_array)
|
||||||
alloc_size = proc_array->alloc_size > 0 ?
|
alloc_size = proc_array->alloc_size > 0 ?
|
||||||
proc_array->alloc_size * 2 : 128;
|
proc_array->alloc_size * 2 : 128;
|
||||||
bytes = sizeof(struct fast_process_info) * alloc_size;
|
bytes = sizeof(struct fast_process_info) * alloc_size;
|
||||||
procs = (struct fast_process_info *)malloc(bytes);
|
procs = (struct fast_process_info *)fc_malloc(bytes);
|
||||||
if (procs == NULL)
|
if (procs == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail", __LINE__, bytes);
|
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -632,14 +631,10 @@ int get_processes(struct fast_process_info **processes, int *count)
|
||||||
}
|
}
|
||||||
|
|
||||||
size = sizeof(struct kinfo_proc) * nproc;
|
size = sizeof(struct kinfo_proc) * nproc;
|
||||||
procs = (struct kinfo_proc *)malloc(size);
|
procs = (struct kinfo_proc *)fc_malloc(size);
|
||||||
if (procs == NULL)
|
if (procs == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
return ENOMEM;
|
||||||
"malloc %d bytes fail, " \
|
|
||||||
"errno: %d, error info: %s", \
|
|
||||||
__LINE__, (int)size, errno, STRERROR(errno));
|
|
||||||
return errno != 0 ? errno : ENOMEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sysctl(mib, 4, procs, &size, NULL, 0) == 0)
|
if (sysctl(mib, 4, procs, &size, NULL, 0) == 0)
|
||||||
|
|
@ -668,11 +663,9 @@ int get_processes(struct fast_process_info **processes, int *count)
|
||||||
nproc = size / sizeof(struct kinfo_proc);
|
nproc = size / sizeof(struct kinfo_proc);
|
||||||
|
|
||||||
bytes = sizeof(struct fast_process_info) * nproc;
|
bytes = sizeof(struct fast_process_info) * nproc;
|
||||||
*processes = (struct fast_process_info *)malloc(bytes);
|
*processes = (struct fast_process_info *)fc_malloc(bytes);
|
||||||
if (*processes == NULL)
|
if (*processes == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"malloc %d bytes fail", __LINE__, bytes);
|
|
||||||
free(procs);
|
free(procs);
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "fc_memory.h"
|
||||||
#include "uniq_skiplist.h"
|
#include "uniq_skiplist.h"
|
||||||
|
|
||||||
static int best_element_counts[SKIPLIST_MAX_LEVEL_COUNT] = {0};
|
static int best_element_counts[SKIPLIST_MAX_LEVEL_COUNT] = {0};
|
||||||
|
|
@ -75,12 +76,9 @@ int uniq_skiplist_init_ex2(UniqSkiplistFactory *factory,
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = sizeof(struct fast_mblock_man) * max_level_count;
|
bytes = sizeof(struct fast_mblock_man) * max_level_count;
|
||||||
factory->node_allocators = (struct fast_mblock_man *)malloc(bytes);
|
factory->node_allocators = (struct fast_mblock_man *)fc_malloc(bytes);
|
||||||
if (factory->node_allocators == NULL) {
|
if (factory->node_allocators == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
return ENOMEM;
|
||||||
"malloc %d bytes fail, errno: %d, error info: %s",
|
|
||||||
__LINE__, bytes, errno, STRERROR(errno));
|
|
||||||
return errno != 0 ? errno : ENOMEM;
|
|
||||||
}
|
}
|
||||||
memset(factory->node_allocators, 0, bytes);
|
memset(factory->node_allocators, 0, bytes);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue