Skip to content

Commit 401b1c0

Browse files
committed
Fix resource leak in LogcatHelper#getLastLogLine
Thanks: CyberSecurity-NCC Signed-off-by: Muntashir Al-Islam <muntashirakon@riseup.net>
1 parent cd6e3ac commit 401b1c0

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

app/src/main/java/io/github/muntashirakon/AppManager/logcat/helper/LogcatHelper.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,15 @@ public static Process getLogcatProcess(@LogBufferId int buffers) throws IOExcept
5353
@Nullable
5454
public static String getLastLogLine(@LogBufferId int buffers) {
5555
Process dumpLogcatProcess = null;
56-
BufferedReader reader;
5756
String result = null;
5857
try {
5958
dumpLogcatProcess = ProcessCompat.exec(getLogcatArgs(buffers, true));
60-
reader = new BufferedReader(new InputStreamReader(dumpLogcatProcess
61-
.getInputStream()), 8192);
62-
63-
String line;
64-
while ((line = reader.readLine()) != null) {
65-
result = line;
59+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(dumpLogcatProcess
60+
.getInputStream()), 8192)) {
61+
String line;
62+
while ((line = reader.readLine()) != null) {
63+
result = line;
64+
}
6665
}
6766
} catch (IOException e) {
6867
Log.e(TAG, e);

0 commit comments

Comments
 (0)