[PATCH]fix potential memory leaks
This commit is contained in:
@@ -65,6 +65,8 @@ void ex_data_runtime_set_ex_container_schema(struct ex_data_runtime *ex_data_rt,
|
||||
|
||||
struct ex_container *ex_container_new(void *ex_data, void *custom_data);
|
||||
|
||||
void ex_container_free(void *ex_data_runtime, void *ex_container);
|
||||
|
||||
/* ex_data_runtime ex data API */
|
||||
void *ex_data_runtime_row2ex_data(struct ex_data_runtime *ex_data_rt,
|
||||
const char *table_name, const char *row,
|
||||
|
||||
@@ -213,6 +213,8 @@ static void clear_iris_descriptor(struct iris_description *iris_cfg)
|
||||
}
|
||||
|
||||
maat_kv_store_free(iris_cfg->str2int_map);
|
||||
iris_cfg->str2int_map = NULL;
|
||||
|
||||
FREE(iris_cfg->encrypt_algo);
|
||||
FREE(iris_cfg->encrypt_key);
|
||||
|
||||
|
||||
@@ -250,6 +250,7 @@ static int bool_plugin_runtime_update_row(struct bool_plugin_runtime *bool_plugi
|
||||
struct ex_container *ex_container = ex_container_new(ex_data, (void *)expr);
|
||||
ret = ex_data_runtime_add_ex_container(ex_data_rt, key, key_len, ex_container);
|
||||
if (ret < 0) {
|
||||
ex_container_free(ex_data_rt, ex_container);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,15 +165,16 @@ struct ex_container *ex_container_new(void *ex_data, void *custom_data)
|
||||
return ex_container;
|
||||
}
|
||||
|
||||
void ex_container_free(void *user_ctx, void *data)
|
||||
void ex_container_free(void *ex_data_runtime, void *ex_container)
|
||||
{
|
||||
/* schema is NULL if not call ex_data_runtime_set_ex_container_schema */
|
||||
if (NULL == user_ctx || NULL == data) {
|
||||
if (NULL == ex_data_runtime || NULL == ex_container) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct ex_container *container = (struct ex_container *)data;
|
||||
struct ex_container_schema *container_schema = (struct ex_container_schema *)user_ctx;
|
||||
struct ex_container *container = (struct ex_container *)ex_container;
|
||||
struct ex_data_runtime *ex_data_rt = (struct ex_data_runtime *)ex_data_runtime;
|
||||
struct ex_container_schema *container_schema = ex_data_rt->ref_container_schema;
|
||||
|
||||
/* free ex_container->custom_data */
|
||||
if (container->custom_data != NULL && container_schema->custom_data_free != NULL) {
|
||||
@@ -205,8 +206,7 @@ int ex_data_runtime_add_ex_container(struct ex_data_runtime *ex_data_rt,
|
||||
if (NULL == ex_data_rt->htable) {
|
||||
/* ex_data_rt->ref_container_schema has been set */
|
||||
assert(ex_data_rt->ref_container_schema != NULL);
|
||||
ex_data_rt->htable = rcu_hash_new(ex_container_free,
|
||||
ex_data_rt->ref_container_schema,
|
||||
ex_data_rt->htable = rcu_hash_new(ex_container_free, ex_data_rt,
|
||||
ex_data_rt->gc_timeout_s);
|
||||
}
|
||||
|
||||
|
||||
@@ -376,6 +376,7 @@ static int fqdn_plugin_runtime_update_row(struct fqdn_plugin_runtime *fqdn_plugi
|
||||
struct ex_container *ex_container = ex_container_new(ex_data, (void *)fqdn_plugin_rule);
|
||||
ret = ex_data_runtime_add_ex_container(ex_data_rt, key, key_len, ex_container);
|
||||
if (ret < 0) {
|
||||
ex_container_free(ex_data_rt, ex_container);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,6 +333,7 @@ static int ip_plugin_runtime_update_row(struct ip_plugin_runtime *ip_plugin_rt,
|
||||
struct ex_container *ex_container = ex_container_new(ex_data, (void *)ip_plugin_rule);
|
||||
ret = ex_data_runtime_add_ex_container(ex_data_rt, key, key_len, ex_container);
|
||||
if (ret < 0) {
|
||||
ex_container_free(ex_data_rt, ex_container);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,6 +382,7 @@ static int ipport_plugin_runtime_update_row(struct ipport_plugin_runtime *ipport
|
||||
struct ex_container *ex_container = ex_container_new(ex_data, (void *)ipport_item);
|
||||
ret = ex_data_runtime_add_ex_container(ex_data_rt, key, key_len, ex_container);
|
||||
if (ret < 0) {
|
||||
ex_container_free(ex_data_rt, ex_container);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,6 +369,7 @@ static int plugin_runtime_update_row(struct plugin_runtime *plugin_rt,
|
||||
ret = ex_data_runtime_add_ex_container(plugin_rt->ex_data_rt, key, key_len,
|
||||
ex_container);
|
||||
if (ret < 0) {
|
||||
ex_container_free(plugin_rt->ex_data_rt, ex_container);
|
||||
return -1;
|
||||
}
|
||||
plugin_rt->acc_line_num++;
|
||||
|
||||
@@ -61,6 +61,7 @@ static void rcu_hash_garbage_collect_force(struct rcu_hash_table *htable)
|
||||
|
||||
while ((p = TAILQ_FIRST(&(htable->garbage_q))) != NULL) {
|
||||
p->garbage_free(p->garbage);
|
||||
p->garbage = NULL;
|
||||
TAILQ_REMOVE(&(htable->garbage_q), p, entries);
|
||||
FREE(p);
|
||||
htable->garbage_q_len--;
|
||||
@@ -77,6 +78,7 @@ void rcu_hash_garbage_collect_routine(struct rcu_hash_table *htable)
|
||||
if ((now - p->create_time) > htable->gc_timeout_s ||
|
||||
htable->gc_timeout_s == 0) {
|
||||
p->garbage_free(p->garbage);
|
||||
p->garbage = NULL;
|
||||
TAILQ_REMOVE(&(htable->garbage_q), p, entries);
|
||||
FREE(p);
|
||||
htable->garbage_q_len--;
|
||||
@@ -107,6 +109,7 @@ static void rcu_hash_node_free(struct rcu_hash_node *node)
|
||||
|
||||
if (node->data != NULL) {
|
||||
node->htable->data_free_fn(node->htable->user_ctx, node->data);
|
||||
node->data = NULL;
|
||||
}
|
||||
FREE(node);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user