From 6abe6abe939db38ed11d668662537f3dc08cb026 Mon Sep 17 00:00:00 2001 From: pancake Date: Thu, 24 Nov 2016 00:29:34 +0100 Subject: [PATCH] Shrink all arenas before reloading the new reg profile --- libr/include/r_reg.h | 1 + libr/reg/arena.c | 13 +++++++++++++ libr/reg/profile.c | 1 + 3 files changed, 15 insertions(+) diff --git a/libr/include/r_reg.h b/libr/include/r_reg.h index 9c7686e89c..ac46d15676 100644 --- a/libr/include/r_reg.h +++ b/libr/include/r_reg.h @@ -206,6 +206,7 @@ R_API void r_reg_arena_poke(RReg *reg, const ut8 *buf); R_API ut8 *r_reg_arena_dup(RReg *reg, const ut8 *source); R_API const char *r_reg_cond_to_string(int n); R_API int r_reg_cond_from_string(const char *str); +R_API void r_reg_arena_shrink(RReg *reg); #endif #endif diff --git a/libr/reg/arena.c b/libr/reg/arena.c index 016bd9a52f..74a5616eb3 100644 --- a/libr/reg/arena.c +++ b/libr/reg/arena.c @@ -311,3 +311,16 @@ R_API int r_reg_arena_set_bytes(RReg *reg, const char* str) { free (bin_str); return 0; } + +R_API void r_reg_arena_shrink(RReg *reg) { + RListIter *iter; + RRegArena *a; + int i; + for (i = 0; i < R_REG_TYPE_LAST; i++) { + r_list_foreach (reg->regset[i].pool, iter, a) { + free (a->bytes); + a->bytes = malloc (1); + a->size = 1; + } + } +} diff --git a/libr/reg/profile.c b/libr/reg/profile.c index 6f596a9abf..da320bea8e 100644 --- a/libr/reg/profile.c +++ b/libr/reg/profile.c @@ -133,6 +133,7 @@ R_API int r_reg_set_profile_string(RReg *reg, const char *str) { r_reg_arena_pop (reg); // Purge the old registers r_reg_free_internal (reg, true); + r_reg_arena_shrink (reg); // Cache the profile string reg->reg_profile_str = strdup (str);