Skip to content

Commit

Permalink
Release DnsRecords when failing to notify promise (#13437)
Browse files Browse the repository at this point in the history
Motivation:

We need to release the DnsRecords if we didnt transfer ownership to
prevent leaks.

Modifications:

Release DnsRecords when trySuccess(...) returns false

Result:

Correctly release reference counted resources
  • Loading branch information
normanmaurer committed Jun 13, 2023
1 parent 7d5fcf7 commit 79c773c
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import io.netty.resolver.InetNameResolver;
import io.netty.resolver.ResolvedAddressTypes;
import io.netty.util.NetUtil;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.FastThreadLocal;
import io.netty.util.concurrent.Future;
Expand Down Expand Up @@ -905,7 +906,12 @@ private Future<List<DnsRecord>> resolveAll(DnsQuestion question, DnsRecord[] add
}

if (!result.isEmpty()) {
trySuccess(promise, result);
if (!trySuccess(promise, result)) {
// We were not able to transfer ownership, release the records to prevent leaks.
for (DnsRecord r: result) {
ReferenceCountUtil.safeRelease(r);
}
}
return promise;
}
}
Expand Down

0 comments on commit 79c773c

Please sign in to comment.