Merge pull request #1575 from fengzeroz/v2.6

fix(trans): memory leak
This commit is contained in:
fengzeroz
2023-10-09 11:28:57 +08:00
committed by GitHub
2 changed files with 25 additions and 16 deletions
+15 -10
View File
@@ -820,23 +820,27 @@ static inline void neu_resp_read_free(neu_resp_read_group_t *resp)
utarray_free(resp->tags);
}
typedef struct {
uint16_t index;
pthread_mutex_t mtx;
} neu_reqresp_trans_data_ctx_t;
typedef struct {
char driver[NEU_NODE_NAME_LEN];
char group[NEU_GROUP_NAME_LEN];
uint16_t index;
pthread_mutex_t mtx;
UT_array * tags; // neu_resp_tag_value_meta_t
neu_reqresp_trans_data_ctx_t *ctx;
UT_array * tags; // neu_resp_tag_value_meta_t
} neu_reqresp_trans_data_t;
static inline void neu_trans_data_free(neu_reqresp_trans_data_t *data)
{
pthread_mutex_lock(&data->mtx);
if (data->index > 0) {
data->index -= 1;
pthread_mutex_lock(&data->ctx->mtx);
if (data->ctx->index > 0) {
data->ctx->index -= 1;
}
if (data->index == 0) {
if (data->ctx->index == 0) {
utarray_foreach(data->tags, neu_resp_tag_value_meta_t *, tag_value)
{
if (tag_value->value.type == NEU_TYPE_PTR) {
@@ -844,10 +848,11 @@ static inline void neu_trans_data_free(neu_reqresp_trans_data_t *data)
}
}
utarray_free(data->tags);
pthread_mutex_unlock(&data->mtx);
pthread_mutex_destroy(&data->mtx);
pthread_mutex_unlock(&data->ctx->mtx);
pthread_mutex_destroy(&data->ctx->mtx);
free(data->ctx);
} else {
pthread_mutex_unlock(&data->mtx);
pthread_mutex_unlock(&data->ctx->mtx);
}
}
+10 -6
View File
@@ -225,9 +225,10 @@ static void update_im(neu_adapter_t *adapter, const char *group,
if (find != NULL) {
pthread_mutex_lock(&find->apps_mtx);
data->index = utarray_len(find->apps);
if (data->index > 0) {
pthread_mutex_init(&data->mtx, NULL);
data->ctx = calloc(1, sizeof(neu_reqresp_trans_data_ctx_t));
data->ctx->index = utarray_len(find->apps);
if (data->ctx->index > 0) {
pthread_mutex_init(&data->ctx->mtx, NULL);
utarray_foreach(find->apps, sub_app_t *, app)
{
@@ -238,6 +239,7 @@ static void update_im(neu_adapter_t *adapter, const char *group,
}
} else {
utarray_free(data->tags);
free(data->ctx);
}
pthread_mutex_unlock(&find->apps_mtx);
@@ -1271,10 +1273,11 @@ static int report_callback(void *usr_data)
if (utarray_len(data->tags) > 0) {
pthread_mutex_lock(&group->apps_mtx);
data->index = utarray_len(group->apps);
data->ctx = calloc(1, sizeof(neu_reqresp_trans_data_ctx_t));
data->ctx->index = utarray_len(group->apps);
if (data->index > 0) {
pthread_mutex_init(&data->mtx, NULL);
if (data->ctx->index > 0) {
pthread_mutex_init(&data->ctx->mtx, NULL);
utarray_foreach(group->apps, sub_app_t *, app)
{
@@ -1286,6 +1289,7 @@ static int report_callback(void *usr_data)
}
} else {
utarray_free(data->tags);
free(data->ctx);
}
pthread_mutex_unlock(&group->apps_mtx);