Fix Kryo serialization memory leak

Change-Id: I122cb811971aef1a70a73c3335b485125125c66b
diff --git a/utils/misc/src/main/java/org/onlab/util/KryoNamespace.java b/utils/misc/src/main/java/org/onlab/util/KryoNamespace.java
index 63d5363..8ea0c50 100644
--- a/utils/misc/src/main/java/org/onlab/util/KryoNamespace.java
+++ b/utils/misc/src/main/java/org/onlab/util/KryoNamespace.java
@@ -233,13 +233,17 @@
      */
     public byte[] serialize(final Object obj, final int bufferSize) {
         ByteBufferOutput out = new ByteBufferOutput(bufferSize, MAX_BUFFER_SIZE);
-        Kryo kryo = borrow();
         try {
-            kryo.writeClassAndObject(out, obj);
-            out.flush();
-            return out.toBytes();
+            Kryo kryo = borrow();
+            try {
+                kryo.writeClassAndObject(out, obj);
+                out.flush();
+                return out.toBytes();
+            } finally {
+                release(kryo);
+            }
         } finally {
-            release(kryo);
+            out.release();
         }
     }