Fix resource leak in PostImage

ObjectInserter was not closed.

Change-Id: I9e1438141401e38a07eff462a250bbda19c73e7c
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/imagare/PostImage.java b/src/main/java/com/googlesource/gerrit/plugins/imagare/PostImage.java
index c25a242..5d9eb8c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/imagare/PostImage.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/imagare/PostImage.java
@@ -218,15 +218,17 @@
   }
 
   private String getRef(byte[] content, String fileName) {
-    String id = new ObjectInserter.Formatter().idFor(Constants.OBJ_BLOB,
-        ArrayUtils.addAll(content, fileName.getBytes())).getName();
-    StringBuilder ref = new StringBuilder();
-    ref.append(Constants.R_REFS);
-    ref.append("images/");
-    ref.append(id.substring(0, 2));
-    ref.append("/");
-    ref.append(id.substring(2));
-    return ref.toString();
+    try (ObjectInserter oi = new ObjectInserter.Formatter()) {
+      String id = oi.idFor(Constants.OBJ_BLOB,
+          ArrayUtils.addAll(content, fileName.getBytes())).getName();
+      StringBuilder ref = new StringBuilder();
+      ref.append(Constants.R_REFS);
+      ref.append("images/");
+      ref.append(id.substring(0, 2));
+      ref.append("/");
+      ref.append(id.substring(2));
+      return ref.toString();
+    }
   }
 
   private String getUrl(Project.NameKey project, String rev, String fileName) {