Skip to content

Commit d901b3b

Browse files
fix(intelligence): fix Process resource leak in RepositoryIdentity.runGit()
Process does not implement AutoCloseable in Java 25, so try-with-resources is not applicable. Use try-finally with proc.destroy() to ensure OS process handles are always released, resolving SonarQube C-Reliability finding. Closes RAN-156 Co-Authored-By: Paperclip <noreply@paperclip.ing>
1 parent 7b30a33 commit d901b3b

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/main/java/io/github/randomcodespace/iq/intelligence/RepositoryIdentity.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ private static String runGit(java.nio.file.Path repoPath, String... args) {
4040
.directory(repoPath.toFile())
4141
.redirectErrorStream(true);
4242
var proc = pb.start();
43-
String out = new String(proc.getInputStream().readAllBytes()).trim();
44-
int exit = proc.waitFor();
45-
return (exit == 0 && !out.isBlank()) ? out : null;
43+
try {
44+
String out = new String(proc.getInputStream().readAllBytes()).trim();
45+
int exit = proc.waitFor();
46+
return (exit == 0 && !out.isBlank()) ? out : null;
47+
} finally {
48+
proc.destroy();
49+
}
4650
} catch (Exception e) {
4751
return null;
4852
}

0 commit comments

Comments
 (0)