bugfix:修复packet io内存泄漏
This commit is contained in:
@@ -195,6 +195,46 @@ static int tap_write(int tap_fd, const char *data, int data_len, void *logger)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct metadata *metadata_new()
|
||||
{
|
||||
struct metadata *meta = (struct metadata *)calloc(1, sizeof(struct metadata));
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
static int metadata_is_empty(struct metadata *meta)
|
||||
{
|
||||
return meta->write_ref == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
static void metadata_deep_copy(struct metadata *dst, struct metadata *src)
|
||||
{
|
||||
dst->write_ref++;
|
||||
dst->session_id = src->session_id;
|
||||
dst->raw_data = (char *)calloc(src->raw_len, sizeof(char));
|
||||
memcpy(dst->raw_data, src->raw_data, src->raw_len);
|
||||
dst->raw_len = src->raw_len;
|
||||
dst->l7offset = src->l7offset;
|
||||
dst->is_e2i_dir = src->is_e2i_dir;
|
||||
dst->is_ctrl_pkt = src->is_ctrl_pkt;
|
||||
dst->is_decrypted = src->is_decrypted;
|
||||
}
|
||||
|
||||
void metadata_free(struct metadata *meta)
|
||||
{
|
||||
if (meta)
|
||||
{
|
||||
if (meta->raw_data)
|
||||
{
|
||||
free(meta->raw_data);
|
||||
meta->raw_data = NULL;
|
||||
}
|
||||
|
||||
free(meta);
|
||||
meta = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static struct session_ctx *session_ctx_new()
|
||||
{
|
||||
struct session_ctx *ctx = (struct session_ctx *)calloc(1, sizeof(struct session_ctx));
|
||||
@@ -211,8 +251,26 @@ static void session_ctx_free(struct session_ctx *ctx)
|
||||
tfe_cmsg_destroy(ctx->cmsg);
|
||||
}
|
||||
|
||||
if (ctx->raw_meta_i2e)
|
||||
{
|
||||
metadata_free(ctx->raw_meta_i2e);
|
||||
ctx->raw_meta_i2e = NULL;
|
||||
}
|
||||
|
||||
if (ctx->raw_meta_e2i)
|
||||
{
|
||||
metadata_free(ctx->raw_meta_e2i);
|
||||
ctx->raw_meta_e2i = NULL;
|
||||
}
|
||||
|
||||
if (ctx->ctrl_meta)
|
||||
{
|
||||
metadata_free(ctx->ctrl_meta);
|
||||
ctx->ctrl_meta = NULL;
|
||||
}
|
||||
|
||||
free(ctx);
|
||||
ctx = 0;
|
||||
ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -501,31 +559,6 @@ static int overwrite_tcp_mss(struct tfe_cmsg *cmsg, struct tcp_restore_info *res
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct metadata *metadata_new()
|
||||
{
|
||||
struct metadata *meta = (struct metadata *)calloc(1, sizeof(struct metadata));
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
static int metadata_is_empty(struct metadata *meta)
|
||||
{
|
||||
return meta->write_ref == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
static void metadata_deep_copy(struct metadata *dst, struct metadata *src)
|
||||
{
|
||||
dst->write_ref++;
|
||||
dst->session_id = src->session_id;
|
||||
dst->raw_data = (char *)calloc(src->raw_len, sizeof(char));
|
||||
memcpy(dst->raw_data, src->raw_data, src->raw_len);
|
||||
dst->raw_len = src->raw_len;
|
||||
dst->l7offset = src->l7offset;
|
||||
dst->is_e2i_dir = src->is_e2i_dir;
|
||||
dst->is_ctrl_pkt = src->is_ctrl_pkt;
|
||||
dst->is_decrypted = src->is_decrypted;
|
||||
}
|
||||
|
||||
static int tcp_restore_set_from_cmsg(struct tfe_cmsg *cmsg, struct tcp_restore_info *restore_info)
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -1270,8 +1303,7 @@ static int handle_session_opening(struct metadata *meta, struct ctrl_pkt_parser
|
||||
ATOMIC_INC(&(packet_io_fs->session_num));
|
||||
return 0;
|
||||
end:
|
||||
if (parser->cmsg)
|
||||
free(parser->cmsg);
|
||||
ctrl_packet_cmsg_destroy(parser);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1358,6 +1390,7 @@ static int handle_control_packet(struct packet_io *handle, marsio_buff_t *rx_buf
|
||||
if (ctrl_parser.session_id != meta.session_id)
|
||||
{
|
||||
TFE_LOG_ERROR(logger, "%s: unexpected control packet, metadata's session %lu != control packet's session %lu", LOG_TAG_PKTIO, meta.session_id, ctrl_parser.session_id);
|
||||
ctrl_packet_cmsg_destroy(&ctrl_parser);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1505,8 +1538,13 @@ void tfe_tap_ctx_destory(struct tap_ctx *handler)
|
||||
tap_close(handler->tap_fd);
|
||||
tap_close(handler->tap_c);
|
||||
tap_close(handler->tap_s);
|
||||
if (handler->buff) {
|
||||
free(handler->buff);
|
||||
handler->buff = NULL;
|
||||
}
|
||||
|
||||
free(handler);
|
||||
handler = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user