Madan Jampani
Committed by Gerrit Code Review

Fix Kryo serialization memory leak

Change-Id: I122cb811971aef1a70a73c3335b485125125c66b
...@@ -233,13 +233,17 @@ public final class KryoNamespace implements KryoFactory, KryoPool { ...@@ -233,13 +233,17 @@ public final class KryoNamespace implements KryoFactory, KryoPool {
233 */ 233 */
234 public byte[] serialize(final Object obj, final int bufferSize) { 234 public byte[] serialize(final Object obj, final int bufferSize) {
235 ByteBufferOutput out = new ByteBufferOutput(bufferSize, MAX_BUFFER_SIZE); 235 ByteBufferOutput out = new ByteBufferOutput(bufferSize, MAX_BUFFER_SIZE);
236 - Kryo kryo = borrow();
237 try { 236 try {
238 - kryo.writeClassAndObject(out, obj); 237 + Kryo kryo = borrow();
239 - out.flush(); 238 + try {
240 - return out.toBytes(); 239 + kryo.writeClassAndObject(out, obj);
240 + out.flush();
241 + return out.toBytes();
242 + } finally {
243 + release(kryo);
244 + }
241 } finally { 245 } finally {
242 - release(kryo); 246 + out.release();
243 } 247 }
244 } 248 }
245 249
......