Release the buffer only after we are done with it 84/77084/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 18 Oct 2018 15:25:55 +0000 (17:25 +0200)
committerRobert Varga <nite@hq.sk>
Thu, 18 Oct 2018 15:29:29 +0000 (15:29 +0000)
We may end up touching the buffer after we have release()'d it,
which means it may have been recycled by the time we call
resetReaderIndex().

Move the release() call to after the check so we do not end up
releasing it prematurely.

Change-Id: I43156dbe2e6c53a552a322e7b5ea27f8da3873c2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java

index bab4a7be632ffd58b98bb0208c8096bdffd5d4a5..96e54942dfac06cc9d9a779ea8a1f4e0ad5e83c2 100644 (file)
@@ -106,14 +106,14 @@ public final class AsyncSshHandlerWriter implements AutoCloseable {
                         promise.setFailure(future.getException());
                     }
 
-                    // Not needed anymore, release
-                    byteBufMsg.release();
-
                     //rescheduling message from queue after successfully sent
                     if (wasPending) {
                         byteBufMsg.resetReaderIndex();
                         pending.remove();
                     }
+
+                    // Not needed anymore, release
+                    byteBufMsg.release();
                 }
 
                 // Check pending queue and schedule next