perf: 删除无效代码;修改变量命名;减少内存分配
This commit is contained in:
@@ -9,14 +9,7 @@
|
||||
* Struct Metadata
|
||||
******************************************************************************/
|
||||
|
||||
struct metadata *metadata_new()
|
||||
{
|
||||
struct metadata *meta = (struct metadata *)calloc(1, sizeof(struct metadata));
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
int metadata_is_empty(struct metadata *meta)
|
||||
int metadata_isempty(struct metadata *meta)
|
||||
{
|
||||
if (meta->write_ref == 0)
|
||||
{
|
||||
@@ -28,7 +21,7 @@ int metadata_is_empty(struct metadata *meta)
|
||||
}
|
||||
}
|
||||
|
||||
void metadata_shallow_copy(struct metadata *dst, struct metadata *src)
|
||||
void metadata_copy(struct metadata *dst, struct metadata *src)
|
||||
{
|
||||
dst->write_ref++;
|
||||
dst->session_id = src->session_id;
|
||||
@@ -36,7 +29,7 @@ void metadata_shallow_copy(struct metadata *dst, struct metadata *src)
|
||||
dst->raw_data = NULL;
|
||||
dst->raw_len = 0;
|
||||
dst->l7offset = src->l7offset;
|
||||
dst->is_e2i_dir = src->is_e2i_dir;
|
||||
dst->direction = src->direction;
|
||||
dst->is_ctrl_pkt = src->is_ctrl_pkt;
|
||||
dst->is_decrypted = src->is_decrypted;
|
||||
|
||||
@@ -44,28 +37,16 @@ void metadata_shallow_copy(struct metadata *dst, struct metadata *src)
|
||||
route_ctx_copy(&dst->route_ctx, &src->route_ctx);
|
||||
}
|
||||
|
||||
void metadata_deep_copy(struct metadata *dst, struct metadata *src)
|
||||
char *memdup(const char *src, int len)
|
||||
{
|
||||
metadata_shallow_copy(dst, src);
|
||||
|
||||
dst->raw_data = (char *)calloc(src->raw_len + 1, sizeof(char));
|
||||
memcpy(dst->raw_data, src->raw_data, src->raw_len);
|
||||
dst->raw_len = src->raw_len;
|
||||
}
|
||||
|
||||
void metadata_free(struct metadata *meta)
|
||||
{
|
||||
if (meta)
|
||||
if (src == NULL || len == 0)
|
||||
{
|
||||
if (meta->raw_data)
|
||||
{
|
||||
free(meta->raw_data);
|
||||
meta->raw_data = NULL;
|
||||
}
|
||||
|
||||
free(meta);
|
||||
meta = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *dst = (char *)calloc(len + 1, sizeof(char));
|
||||
memcpy(dst, src, len);
|
||||
return dst;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@@ -78,13 +59,6 @@ struct session_ctx *session_ctx_new()
|
||||
assert(session_ctx != NULL);
|
||||
|
||||
mutable_array_init(&session_ctx->rule_ids);
|
||||
|
||||
session_ctx->decrypted_meta_i2e = metadata_new();
|
||||
session_ctx->decrypted_meta_e2i = metadata_new();
|
||||
session_ctx->raw_meta_i2e = metadata_new();
|
||||
session_ctx->raw_meta_e2i = metadata_new();
|
||||
session_ctx->ctrl_meta = metadata_new();
|
||||
|
||||
return session_ctx;
|
||||
}
|
||||
|
||||
@@ -98,46 +72,22 @@ void session_ctx_free(struct session_ctx *session_ctx)
|
||||
session_ctx->session_addr = NULL;
|
||||
}
|
||||
|
||||
if (session_ctx->decrypted_meta_i2e)
|
||||
if (session_ctx->ctrl_packet_header_data)
|
||||
{
|
||||
metadata_free(session_ctx->decrypted_meta_i2e);
|
||||
session_ctx->decrypted_meta_i2e = NULL;
|
||||
free(session_ctx->ctrl_packet_header_data);
|
||||
session_ctx->ctrl_packet_header_data = NULL;
|
||||
}
|
||||
|
||||
if (session_ctx->decrypted_meta_e2i)
|
||||
if (session_ctx->chaining_raw)
|
||||
{
|
||||
metadata_free(session_ctx->decrypted_meta_e2i);
|
||||
session_ctx->decrypted_meta_e2i = NULL;
|
||||
selected_chaining_destory(session_ctx->chaining_raw);
|
||||
session_ctx->chaining_raw = NULL;
|
||||
}
|
||||
|
||||
if (session_ctx->raw_meta_i2e)
|
||||
if (session_ctx->chaining_decrypted)
|
||||
{
|
||||
metadata_free(session_ctx->raw_meta_i2e);
|
||||
session_ctx->raw_meta_i2e = NULL;
|
||||
}
|
||||
|
||||
if (session_ctx->raw_meta_e2i)
|
||||
{
|
||||
metadata_free(session_ctx->raw_meta_e2i);
|
||||
session_ctx->raw_meta_e2i = NULL;
|
||||
}
|
||||
|
||||
if (session_ctx->ctrl_meta)
|
||||
{
|
||||
metadata_free(session_ctx->ctrl_meta);
|
||||
session_ctx->ctrl_meta = NULL;
|
||||
}
|
||||
|
||||
if (session_ctx->chainings.chaining_raw)
|
||||
{
|
||||
selected_chaining_destory(session_ctx->chainings.chaining_raw);
|
||||
session_ctx->chainings.chaining_raw = NULL;
|
||||
}
|
||||
|
||||
if (session_ctx->chainings.chaining_decrypted)
|
||||
{
|
||||
selected_chaining_destory(session_ctx->chainings.chaining_decrypted);
|
||||
session_ctx->chainings.chaining_decrypted = NULL;
|
||||
selected_chaining_destory(session_ctx->chaining_decrypted);
|
||||
session_ctx->chaining_decrypted = NULL;
|
||||
}
|
||||
|
||||
free(session_ctx);
|
||||
@@ -175,7 +125,7 @@ struct sce_ctx *sce_ctx_create(const char *profile)
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
sce_ctx->enforcer = policy_enforcer_create("SCE", profile, sce_ctx->nr_worker_threads, NULL);
|
||||
sce_ctx->enforcer = policy_enforcer_create("SCE", profile, sce_ctx->nr_worker_threads);
|
||||
if (sce_ctx->enforcer == NULL)
|
||||
{
|
||||
goto error_out;
|
||||
|
||||
Reference in New Issue
Block a user