fix leak memory

This commit is contained in:
liuwentan
2023-04-04 09:31:20 +08:00
parent a13af5c699
commit d3d19a4fe9
11 changed files with 46 additions and 32 deletions

View File

@@ -43,7 +43,7 @@ struct ex_data_runtime;
/* ex_data_runtime API */
struct ex_data_runtime *
ex_data_runtime_new(int table_id, rcu_hash_data_free_fn *data_free_fn,
struct maat_garbage_bin *garbage_bin, struct log_handle *logger);
struct log_handle *logger);
void ex_data_runtime_free(struct ex_data_runtime *ex_data_rt);
void ex_data_runtime_commit(struct ex_data_runtime *ex_data_rt);

View File

@@ -11,6 +11,7 @@
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <linux/limits.h>
#include "maat_utils.h"
@@ -438,7 +439,9 @@ void maat_free(struct maat *maat_instance)
}
void *ret = NULL;
while (0 == maat_instance->is_running) {
usleep(500 * 1000);
}
maat_instance->is_running = 0;
pthread_join(maat_instance->cfg_mon_thread, &ret);
}

View File

@@ -189,7 +189,7 @@ void *bool_plugin_runtime_new(void *bool_plugin_schema, int max_thread_num,
bool_plugin_rt->ex_data_rt = ex_data_runtime_new(schema->table_id,
ex_container_free,
garbage_bin, logger);
logger);
bool_plugin_rt->ref_garbage_bin = garbage_bin;
bool_plugin_rt->logger = logger;

View File

@@ -858,7 +858,7 @@ int compare_literal_id(const void *pa, const void *pb)
struct maat_literal_id *la = (struct maat_literal_id *)pa;
struct maat_literal_id *lb = (struct maat_literal_id *)pb;
int ret = la->vtable_id - lb->vtable_id;
long long ret = la->vtable_id - lb->vtable_id;
if (0 == ret) {
ret = la->group_id - lb->group_id;
}
@@ -927,7 +927,7 @@ maat_clause_hash_fetch_clause(struct compile_runtime *compile_rt,
HASH_FIND(hh, compile_rt->clause_by_literals_hash, literal_ids,
n_literal_id * sizeof(struct maat_literal_id), clause);
if (!clause) {
if (NULL == clause) {
clause = ALLOC(struct maat_clause, 1);
clause->clause_id = maat_runtime_get_sequence(compile_rt->ref_maat_rt, "clause_id");
clause->n_literal_id = n_literal_id;

View File

@@ -25,7 +25,6 @@ struct ex_data_runtime {
size_t cache_size;
struct rcu_hash_table *htable;
struct maat_garbage_bin *ref_garbage_bin;
int table_id;
struct log_handle *logger;
@@ -40,10 +39,9 @@ UT_icd ut_cache_row_icd = {sizeof(char*), NULL, NULL, cache_row_free};
struct ex_data_runtime *
ex_data_runtime_new(int table_id, rcu_hash_data_free_fn *data_free_fn,
struct maat_garbage_bin *garbage_bin, struct log_handle *logger)
struct log_handle *logger)
{
if (NULL == data_free_fn || NULL == garbage_bin ||
NULL == logger) {
if (NULL == data_free_fn || NULL == logger) {
return NULL;
}
@@ -52,7 +50,6 @@ ex_data_runtime_new(int table_id, rcu_hash_data_free_fn *data_free_fn,
utarray_new(ex_data_rt->cache_rows, &ut_cache_row_icd);
ex_data_rt->htable = rcu_hash_new(data_free_fn);
ex_data_rt->table_id = table_id;
ex_data_rt->ref_garbage_bin = garbage_bin;
ex_data_rt->logger = logger;
return ex_data_rt;
@@ -203,25 +200,26 @@ struct ex_container *ex_container_new(void *ex_data, void *custom_data)
void ex_container_free(void *schema, void *data)
{
/* schema is NULL if not call ex_data_runtime_set_ex_container_schema */
if (NULL == schema || NULL == data) {
if (NULL == data) {
return;
}
struct ex_container *ex_container = (struct ex_container *)data;
struct ex_container_schema *container_schema = (struct ex_container_schema *)schema;
long argl = container_schema->ex_schema->argl;
void *argp = container_schema->ex_schema->argp;
if (ex_container->ex_data != NULL
&& container_schema->ex_schema->free_func != NULL) {
container_schema->ex_schema->free_func(container_schema->table_id,
&(ex_container->ex_data), argl, argp);
}
if (ex_container->custom_data != NULL) {
FREE(ex_container->custom_data);
}
struct ex_container_schema *container_schema = (struct ex_container_schema *)schema;
if (container_schema != NULL && container_schema->ex_schema != NULL) {
long argl = container_schema->ex_schema->argl;
void *argp = container_schema->ex_schema->argp;
if (ex_container->ex_data != NULL && container_schema->ex_schema->free_func != NULL) {
container_schema->ex_schema->free_func(container_schema->table_id,
&(ex_container->ex_data), argl, argp);
}
}
FREE(ex_container);
}

View File

@@ -173,7 +173,7 @@ void *fqdn_plugin_runtime_new(void *fqdn_plugin_schema, int max_thread_num,
struct fqdn_plugin_runtime *fqdn_plugin_rt = ALLOC(struct fqdn_plugin_runtime, 1);
fqdn_plugin_rt->ex_data_rt = ex_data_runtime_new(schema->table_id, ex_container_free,
garbage_bin, logger);
logger);
fqdn_plugin_rt->ref_garbage_bin = garbage_bin;
fqdn_plugin_rt->logger = logger;

View File

@@ -403,6 +403,11 @@ void ip_runtime_free(void *ip_runtime)
ip_rt->ip_matcher = NULL;
}
if (ip_rt->intval_matcher != NULL) {
interval_matcher_free(ip_rt->intval_matcher);
ip_rt->intval_matcher = NULL;
}
if (ip_rt->htable != NULL) {
rcu_hash_free(ip_rt->htable);
ip_rt->htable = NULL;
@@ -614,6 +619,10 @@ int ip_runtime_commit(void *ip_runtime, const char *table_name)
FREE(rules);
}
if (intval_rules != NULL) {
FREE(intval_rules);
}
if (ex_data_array != NULL) {
FREE(ex_data_array);
}

View File

@@ -358,7 +358,7 @@ void *ip_plugin_runtime_new(void *ip_plugin_schema, int max_thread_num,
struct ip_plugin_runtime *ip_plugin_rt = ALLOC(struct ip_plugin_runtime, 1);
ip_plugin_rt->ex_data_rt = ex_data_runtime_new(schema->table_id, ex_container_free,
garbage_bin, logger);
logger);
ip_plugin_rt->ref_garbage_bin = garbage_bin;
ip_plugin_rt->logger = logger;

View File

@@ -267,7 +267,7 @@ void *plugin_runtime_new(void *plugin_schema, int max_thread_num,
struct plugin_runtime *plugin_rt = ALLOC(struct plugin_runtime, 1);
plugin_rt->ex_data_rt = ex_data_runtime_new(schema->table_id,
ex_container_free,
garbage_bin, logger);
logger);
plugin_rt->ref_garbage_bin = garbage_bin;
plugin_rt->logger = logger;