Shrink all arenas before reloading the new reg profile

This commit is contained in:
pancake 2016-11-24 00:29:34 +01:00
parent 2c27fd9b41
commit 6abe6abe93
3 changed files with 15 additions and 0 deletions

View File

@ -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

View File

@ -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;
}
}
}

View File

@ -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);