mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
Core: Fix memory leaks with RequireFeatures() (#4095)
Fixes https://github.com/XTLS/Xray-core/issues/4054 Fixes https://github.com/XTLS/Xray-core/issues/3338 Fixes https://github.com/XTLS/Xray-core/issues/3221
This commit is contained in:
parent
a2b773135a
commit
0e2304c403
15 changed files with 98 additions and 59 deletions
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
|
||||
"github.com/xtls/xray-core/app/observatory"
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/core"
|
||||
"github.com/xtls/xray-core/features/extension"
|
||||
|
@ -21,19 +20,19 @@ func (l *LeastPingStrategy) GetPrincipleTarget(strings []string) []string {
|
|||
|
||||
func (l *LeastPingStrategy) InjectContext(ctx context.Context) {
|
||||
l.ctx = ctx
|
||||
core.RequireFeaturesAsync(l.ctx, func(observatory extension.Observatory) {
|
||||
l.observatory = observatory
|
||||
})
|
||||
}
|
||||
|
||||
func (l *LeastPingStrategy) PickOutbound(strings []string) string {
|
||||
if l.observatory == nil {
|
||||
common.Must(core.RequireFeatures(l.ctx, func(observatory extension.Observatory) error {
|
||||
l.observatory = observatory
|
||||
return nil
|
||||
}))
|
||||
errors.LogError(l.ctx, "observer is nil")
|
||||
return ""
|
||||
}
|
||||
|
||||
observeReport, err := l.observatory.GetObservation(l.ctx)
|
||||
if err != nil {
|
||||
errors.LogInfoInner(l.ctx, err, "cannot get observe report")
|
||||
errors.LogInfoInner(l.ctx, err, "cannot get observer report")
|
||||
return ""
|
||||
}
|
||||
outboundsList := outboundList(strings)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue