]> source.dussan.org Git - gitblit.git/commitdiff
Properly dispose RevWalk in getCommit
authorJames Moger <james.moger@gitblit.com>
Fri, 28 Feb 2014 19:28:58 +0000 (14:28 -0500)
committerJames Moger <james.moger@gitblit.com>
Sat, 1 Mar 2014 14:21:19 +0000 (09:21 -0500)
src/main/java/com/gitblit/utils/JGitUtils.java

index 212a90af4af57560a5f1f59066e4169a2e144364..7621c0e0adcf40bf6c8b72ff5fa7f357b69e3199 100644 (file)
@@ -704,6 +704,7 @@ public class JGitUtils {
                        return null;\r
                }\r
                RevCommit commit = null;\r
+               RevWalk walk = null;\r
                try {\r
                        // resolve object id\r
                        ObjectId branchObject;\r
@@ -712,12 +713,18 @@ public class JGitUtils {
                        } else {\r
                                branchObject = repository.resolve(objectId);\r
                        }\r
-                       RevWalk walk = new RevWalk(repository);\r
+                       if (branchObject == null) {\r
+                               return null;\r
+                       }\r
+                       walk = new RevWalk(repository);\r
                        RevCommit rev = walk.parseCommit(branchObject);\r
                        commit = rev;\r
-                       walk.dispose();\r
                } catch (Throwable t) {\r
                        error(t, repository, "{0} failed to get commit {1}", objectId);\r
+               } finally {\r
+                       if (walk != null) {\r
+                               walk.dispose();\r
+                       }\r
                }\r
                return commit;\r
        }\r