state: explicitly free resources on Close()

This commit is contained in:
WeebDataHoarder
2025-05-01 14:16:19 +02:00
parent d80e282781
commit d412672ed4
2 changed files with 25 additions and 4 deletions

View File

@@ -54,9 +54,8 @@ type State struct {
Mux *http.ServeMux
}
func NewState(p policy.Policy, opt settings.Settings, settings policy.StateSettings) (handler http.Handler, err error) {
state := new(State)
func NewState(p policy.Policy, opt settings.Settings, settings policy.StateSettings) (state *State, err error) {
state = new(State)
state.close = make(chan struct{})
state.settings = settings
state.opt = opt
@@ -273,3 +272,21 @@ func NewState(p policy.Policy, opt settings.Settings, settings policy.StateSetti
return state, nil
}
func (state *State) Close() error {
select {
case <-state.close:
default:
close(state.close)
for _, c := range state.challenges {
if c.Object != nil {
err := c.Object.Close()
if err != nil {
return err
}
}
}
}
return nil
}