Limit op cache in type matching (#3297)

Reduces the peak memory usage of the corkami virtgap.exe test from
1.177GB to 241.9MB (measured with massif).
This commit is contained in:
Florian Märkl 2023-01-17 08:54:37 +01:00 committed by GitHub
parent 30f4d77088
commit 8f1fdc91d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -809,6 +809,8 @@ void propagate_types_among_used_variables(RzCore *core, HtUP *op_cache, RzAnalys
}
}
#define OP_CACHE_LIMIT 8192
RZ_API void rz_core_analysis_type_match(RzCore *core, RzAnalysisFunction *fcn, HtUU *loop_table) {
RzListIter *it;
@ -925,6 +927,15 @@ RZ_API void rz_core_analysis_type_match(RzCore *core, RzAnalysisFunction *fcn, H
}
addr += aop->size;
rz_list_free(fcns);
// Recreate op_cache if it grows too large to avoid
// excessive memory usage.
if (op_cache->count > OP_CACHE_LIMIT) {
ht_up_free(op_cache);
op_cache = ht_up_new(NULL, free_op_cache_kv, NULL);
if (!op_cache) {
break;
}
}
}
}