diff options
Diffstat (limited to 'usr.sbin/relayd')
-rw-r--r-- | usr.sbin/relayd/subagentx.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/usr.sbin/relayd/subagentx.c b/usr.sbin/relayd/subagentx.c index 6c392a1cb63..ccb9684196b 100644 --- a/usr.sbin/relayd/subagentx.c +++ b/usr.sbin/relayd/subagentx.c @@ -1729,6 +1729,7 @@ void subagentx_index_free(struct subagentx_index *sai) { size_t i; + struct subagentx_object *sao; if (sai == NULL) return; @@ -1737,14 +1738,18 @@ subagentx_index_free(struct subagentx_index *sai) subagentx_log_sac_fatalx(sai->sai_sar->sar_sac, "%s: double free", __func__); - sai->sai_dstate = SA_DSTATE_CLOSE; - /* TODO Do a range_subid unregister before freeing */ for (i = 0; i < sai->sai_objectlen; i++) { - if (sai->sai_object[i]->sao_dstate != SA_DSTATE_CLOSE) - subagentx_object_free(sai->sai_object[i]); + sao = sai->sai_object[i]; + if (sao->sao_dstate != SA_DSTATE_CLOSE) { + subagentx_object_free(sao); + if (sai->sai_object[i] != sao) + i--; + } } + sai->sai_dstate = SA_DSTATE_CLOSE; + if (sai->sai_cstate == SA_CSTATE_OPEN) (void) subagentx_index_close(sai); else if (sai->sai_cstate == SA_CSTATE_CLOSE) @@ -2415,7 +2420,8 @@ subagentx_object_free_finalize(struct subagentx_object *sao) "%s: object not found in index", __func__); #endif sao->sao_index[i]->sai_objectlen--; - if (sao->sao_index[i]->sai_dstate == SA_DSTATE_CLOSE) + if (sao->sao_index[i]->sai_dstate == SA_DSTATE_CLOSE && + sao->sao_index[i]->sai_cstate == SA_CSTATE_CLOSE) subagentx_index_free_finalize(sao->sao_index[i]); } |