From: Vsevolod Stakhov Date: Fri, 18 Oct 2019 10:34:49 +0000 (+0100) Subject: [Fix] Fix use-after-free X-Git-Tag: 2.1~77 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f41ac57b3a61a1abfe562a930734a45f36ba5604;p=rspamd.git [Fix] Fix use-after-free --- diff --git a/src/libutil/map_helpers.c b/src/libutil/map_helpers.c index 9f3dacad8..a9bd8d70e 100644 --- a/src/libutil/map_helpers.c +++ b/src/libutil/map_helpers.c @@ -770,15 +770,6 @@ rspamd_map_helper_destroy_regexp (struct rspamd_regexp_map_helper *re_map) return; } - for (i = 0; i < re_map->regexps->len; i ++) { - re = g_ptr_array_index (re_map->regexps, i); - rspamd_regexp_unref (re); - } - - g_ptr_array_free (re_map->regexps, TRUE); - g_ptr_array_free (re_map->values, TRUE); - kh_destroy (rspamd_map_hash, re_map->htb); - #ifdef WITH_HYPERSCAN if (re_map->hs_scratch) { hs_free_scratch (re_map->hs_scratch); @@ -801,6 +792,15 @@ rspamd_map_helper_destroy_regexp (struct rspamd_regexp_map_helper *re_map) } #endif + for (i = 0; i < re_map->regexps->len; i ++) { + re = g_ptr_array_index (re_map->regexps, i); + rspamd_regexp_unref (re); + } + + g_ptr_array_free (re_map->regexps, TRUE); + g_ptr_array_free (re_map->values, TRUE); + kh_destroy (rspamd_map_hash, re_map->htb); + rspamd_mempool_t *pool = re_map->pool; memset (re_map, 0, sizeof (*re_map)); rspamd_mempool_delete (pool);