Ensure we release the previous retained AddressedEnvelope when we fail to notify the promise.

Motivation:

We need to ensure we release the AddressedEnvelope if we fail to notify the future (as it may be notified before because of an timeout). Otherwise we may leak.

Modifications:

Call release() if we fail to notify the future.

Result:

No more memory leak on notify failure.
This commit is contained in:
Norman Maurer 2017-01-25 12:51:06 +01:00
parent 14b902fced
commit 3462a86a3a

View File

@ -191,7 +191,10 @@ final class DnsQueryContext {
@SuppressWarnings("unchecked")
AddressedEnvelope<DnsResponse, InetSocketAddress> castResponse =
(AddressedEnvelope<DnsResponse, InetSocketAddress>) envelope.retain();
promise.setSuccess(castResponse);
if (!promise.trySuccess(castResponse)) {
// We failed to notify the promise as it was failed before, thus we need to release the envelope
envelope.release();
}
}
}