]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/util/DNSUtil.java
Fix: exceptional resource leaks from coverty
[gigi.git] / src / org / cacert / gigi / util / DNSUtil.java
index 7ebbf83d48e9a8b97f9657fc64ae68044110b838..f1d5f9f3a86f9415aed483486ae857c5764c9dc2 100644 (file)
@@ -36,13 +36,16 @@ public class DNSUtil {
         env.put(Context.AUTHORITATIVE, "true");
         env.put(Context.PROVIDER_URL, "dns://" + server);
         InitialDirContext context = new InitialDirContext(env);
+        try {
 
-        Attributes dnsLookup = context.getAttributes(name, new String[] {
-            "TXT"
-        });
-        context.close();
+            Attributes dnsLookup = context.getAttributes(name, new String[] {
+                "TXT"
+            });
+            return extractTextEntries(dnsLookup.get("TXT"));
+        } finally {
+            context.close();
+        }
 
-        return extractTextEntries(dnsLookup.get("TXT"));
     }
 
     private static String[] extractTextEntries(Attribute nsRecords) throws NamingException {