From fe73ef1156d170d3f707d70bcf4f49cfec08131a Mon Sep 17 00:00:00 2001 From: zhengchao Date: Tue, 1 Jun 2021 21:40:20 +0800 Subject: [PATCH] =?UTF-8?q?Hierarchy=E4=B8=AD=EF=BC=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=9E=83=E5=9C=BE=E5=9B=9E=E6=94=B6=E6=96=B9=E5=BC=8F=E9=87=8A?= =?UTF-8?q?=E6=94=BEcompile=EF=BC=8C=E9=81=BF=E5=85=8Dbool=5Fmatcher?= =?UTF-8?q?=E5=91=BD=E4=B8=AD=E5=B7=B2=E5=88=A0=E9=99=A4=E7=9A=84compile?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E4=BB=8E=E8=80=8C=E9=9D=9E=E6=B3=95=E5=86=85?= =?UTF-8?q?=E5=AD=98=E8=AE=BF=E9=97=AE=E5=AF=BC=E8=87=B4=E6=AE=B5=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E3=80=82=20=E4=BF=AE=E5=A4=8D=20TSG-6548?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entry/Maat_hierarchy.cpp | 39 ++++++++++++++++++------------- src/entry/Maat_rule.cpp | 2 +- src/inc_internal/Maat_hierarchy.h | 3 ++- test/test_maatframe.cpp | 2 +- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/entry/Maat_hierarchy.cpp b/src/entry/Maat_hierarchy.cpp index 67db3c7..3387a50 100644 --- a/src/entry/Maat_hierarchy.cpp +++ b/src/entry/Maat_hierarchy.cpp @@ -2,7 +2,6 @@ #include "Maat_hierarchy.h" #include "Maat_utils.h" #include "Maat_limits.h" - #include "uthash/uthash.h" #include "uthash/utarray.h" #include "igraph/igraph.h" @@ -122,7 +121,7 @@ struct Maat_hierarchy igraph_integer_t grp_vertex_id_generator; int thread_num; - struct Maat_garbage_bin* garbage_bin; + struct Maat_garbage_bin* ref_garbage_bin; void* logger; void **expr_match_buff; }; @@ -285,16 +284,12 @@ static struct Maat_hierarchy_compile* Maat_hierarchy_compile_new(struct Maat_hie } return compile; } -static void Maat_hierarchy_compile_free(struct Maat_hierarchy* hier, struct Maat_hierarchy_compile* compile) +static void Maat_hierarchy_compile_free(struct Maat_hierarchy_compile* compile) { int i=0; struct Maat_hierarchy_clause_state* clause_state=NULL; - HASH_DEL(hier->hash_compile_by_id, compile); - if(compile->user_data && hier->compile_user_data_free) - { - hier->compile_user_data_free(compile->user_data); - compile->user_data=NULL; - } + //user_data must be freed before calling this function. + assert(compile->user_data==NULL); for(i=0; iclause_states+i; @@ -333,7 +328,7 @@ static void Maat_hierarchy_region_free(struct Maat_hierarchy* hier, struct Maat_ } -struct Maat_hierarchy* Maat_hierarchy_new(int thread_num, void* mesa_handle_logger) +struct Maat_hierarchy* Maat_hierarchy_new(int thread_num, void* mesa_handle_logger, struct Maat_garbage_bin* bin) { struct Maat_hierarchy* hier=ALLOC(struct Maat_hierarchy, 1); int ret=0; @@ -348,7 +343,7 @@ struct Maat_hierarchy* Maat_hierarchy_new(int thread_num, void* mesa_handle_logg hier->hash_region_by_id=NULL; hier->hash_dedup_clause_by_literals=NULL; hier->clause_id_generator=0; - + hier->ref_garbage_bin=bin; hier->expr_match_buff=ALLOC(void*, thread_num*MAX_SCANNER_HIT_NUM); ret=igraph_empty(&hier->group_graph, 0, IGRAPH_DIRECTED); @@ -371,7 +366,13 @@ void Maat_hierarchy_free(struct Maat_hierarchy* hier) //and sets its pointer to NULL. HASH_ITER(hh, hier->hash_compile_by_id, compile, tmp_compile) { - Maat_hierarchy_compile_free(hier, compile); + if(hier->compile_user_data_free && compile->user_data) + { + hier->compile_user_data_free(compile->user_data); + compile->user_data=NULL; + } + HASH_DEL(hier->hash_compile_by_id, compile); + Maat_hierarchy_compile_free(compile); } assert(hier->hash_compile_by_id==NULL); @@ -468,8 +469,9 @@ int Maat_hierarchy_compile_remove(struct Maat_hierarchy * hier, int compile_id) compile->user_data=NULL; } if(compile->actual_clause_num==0) - { - Maat_hierarchy_compile_free(hier, compile); + { + HASH_DEL(hier->hash_compile_by_id, compile); + Maat_garbage_bagging(hier->ref_garbage_bin, compile, (void (*)(void*))Maat_hierarchy_compile_free); } ret=0; } @@ -673,8 +675,9 @@ int Maat_hierarchy_remove_group_from_compile(struct Maat_hierarchy* hier, int gr goto error_out; } if(compile->actual_clause_num==0 && !compile->user_data) - { - Maat_hierarchy_compile_free(hier, compile); + { + HASH_DEL(hier->hash_compile_by_id, compile); + Maat_garbage_bagging(hier->ref_garbage_bin, compile, (void (*)(void*))Maat_hierarchy_compile_free); } pthread_rwlock_unlock(&hier->rwlock); return 0; @@ -1370,6 +1373,10 @@ int Maat_hierarchy_region_compile(struct Maat_hierarchy* hier, struct Maat_hiera { compile=(struct Maat_hierarchy_compile*)expr_match[i]; assert(compile->magic==MAAT_HIER_COMPILE_MAGIC); + if(compile->actual_clause_num==0) + { + continue; + } r_in_c_cnt=Maat_hierarchy_compile_mid_update_by_compile(hier, mid, compile); if(compile->not_clause_cnt>0 && !is_last_compile) { diff --git a/src/entry/Maat_rule.cpp b/src/entry/Maat_rule.cpp index 40d4527..aa351b2 100644 --- a/src/entry/Maat_rule.cpp +++ b/src/entry/Maat_rule.cpp @@ -759,7 +759,7 @@ struct Maat_scanner* create_maat_scanner(unsigned int version, _Maat_feather_t * struct Maat_scanner* scanner=NULL; scanner=ALLOC(struct Maat_scanner, 1); - scanner->hier=Maat_hierarchy_new(scan_thread_num, feather->logger); + scanner->hier=Maat_hierarchy_new(scan_thread_num, feather->logger, feather->garbage_bin); Maat_hierarchy_set_compile_user_data_free_func(scanner->hier, (void (*)(void*))destroy_compile_rule); Maat_hierarchy_set_region_user_data_free_func(scanner->hier, (void (*)(void*))Maat_region_inner_free); diff --git a/src/inc_internal/Maat_hierarchy.h b/src/inc_internal/Maat_hierarchy.h index bcad76d..343d0bf 100644 --- a/src/inc_internal/Maat_hierarchy.h +++ b/src/inc_internal/Maat_hierarchy.h @@ -1,10 +1,11 @@ #pragma once #include "Maat_rule.h" +#include "Maat_garbage_collection.h" #include struct Maat_hierarchy; -struct Maat_hierarchy* Maat_hierarchy_new(int thread_num, void* mesa_handle_logger); +struct Maat_hierarchy* Maat_hierarchy_new(int thread_num, void* mesa_handle_logger, struct Maat_garbage_bin* bin); void Maat_hierarchy_free(struct Maat_hierarchy* hier); void Maat_hierarchy_set_compile_user_data_free_func(struct Maat_hierarchy* hier, void (* func)(void *)); void Maat_hierarchy_set_region_user_data_free_func(struct Maat_hierarchy* hier, void (* func)(void *)); diff --git a/test/test_maatframe.cpp b/test/test_maatframe.cpp index 44872dc..5fba454 100644 --- a/test/test_maatframe.cpp +++ b/test/test_maatframe.cpp @@ -4145,7 +4145,7 @@ TEST_F(MaatCmdTest, CompileDelete_TSG6548) time_t update_time=time(NULL); time_t now=update_time; - while(now-update_time<60) + while(now-update_time<3) { ret=Maat_scan_proto_addr(feather,table_id, &ipv4_addr, 6, result, 4, &mid, 0); if(ret>0)