Fix memory leak caused by requiring component.

This commit is contained in:
pocketW 2022-04-28 14:22:05 +10:00 committed by yuhan6665
parent 00c4b6f44f
commit 3bfd6853f4

View file

@ -14,12 +14,13 @@ import (
// newFakeDNSSniffer Creates a Fake DNS metadata sniffer // newFakeDNSSniffer Creates a Fake DNS metadata sniffer
func newFakeDNSSniffer(ctx context.Context) (protocolSnifferWithMetadata, error) { func newFakeDNSSniffer(ctx context.Context) (protocolSnifferWithMetadata, error) {
var fakeDNSEngine dns.FakeDNSEngine var fakeDNSEngine dns.FakeDNSEngine
err := core.RequireFeatures(ctx, func(fdns dns.FakeDNSEngine) { {
fakeDNSEngine = fdns fakeDNSEngineFeat := core.MustFromContext(ctx).GetFeature(fakeDNSEngine)
}) if fakeDNSEngineFeat != nil {
if err != nil { fakeDNSEngine = fakeDNSEngineFeat.(dns.FakeDNSEngine)
return protocolSnifferWithMetadata{}, err
} }
}
if fakeDNSEngine == nil { if fakeDNSEngine == nil {
errNotInit := newError("FakeDNSEngine is not initialized, but such a sniffer is used").AtError() errNotInit := newError("FakeDNSEngine is not initialized, but such a sniffer is used").AtError()
return protocolSnifferWithMetadata{}, errNotInit return protocolSnifferWithMetadata{}, errNotInit