From 3462a86a3ac41230965e3f06d527da6db9b39e04 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 25 Jan 2017 12:51:06 +0100 Subject: [PATCH] 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. --- .../src/main/java/io/netty/resolver/dns/DnsQueryContext.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/resolver-dns/src/main/java/io/netty/resolver/dns/DnsQueryContext.java b/resolver-dns/src/main/java/io/netty/resolver/dns/DnsQueryContext.java index 6b98f36e8c..5439fb82b1 100644 --- a/resolver-dns/src/main/java/io/netty/resolver/dns/DnsQueryContext.java +++ b/resolver-dns/src/main/java/io/netty/resolver/dns/DnsQueryContext.java @@ -191,7 +191,10 @@ final class DnsQueryContext { @SuppressWarnings("unchecked") AddressedEnvelope castResponse = (AddressedEnvelope) 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(); + } } }