Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f62c6e38 authored by Flamefire's avatar Flamefire Committed by Alex Grund
Browse files

Fix resource leaks

Change-Id: I3a201cfd924e467d605351782bd06874c2af725e
parent 78a29672
Loading
Loading
Loading
Loading
+24 −17
Original line number Diff line number Diff line
@@ -53,7 +53,6 @@ import java.security.spec.EncodedKeySpec;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
@@ -658,6 +657,7 @@ public class PackageParser {

        try {
            final ZipFile privateZip = new ZipFile(originalFile.getPath());
            try {
                final Enumeration<? extends ZipEntry> privateZipEntries = privateZip.entries();
                while (privateZipEntries.hasMoreElements()) {
                    final ZipEntry zipEntry = privateZipEntries.nextElement();
@@ -668,6 +668,9 @@ public class PackageParser {
                        overlayTargets.add(subdirs[2]);
                    }
                }
            } finally {
                privateZip.close();
            }
        } catch(Exception e) {
            e.printStackTrace();
            overlayTargets.clear();
@@ -681,15 +684,20 @@ public class PackageParser {
    private boolean packageHasIconPack(File originalFile) {
        try {
            final ZipFile privateZip = new ZipFile(originalFile.getPath());
            try {
                final Enumeration<? extends ZipEntry> privateZipEntries = privateZip.entries();
                while (privateZipEntries.hasMoreElements()) {
                    final ZipEntry zipEntry = privateZipEntries.nextElement();
                    final String zipEntryName = zipEntry.getName();

                if (zipEntryName.startsWith(ICON_PATH) && zipEntryName.length() > ICON_PATH.length()) {
                    if (zipEntryName.startsWith(ICON_PATH)
                            && zipEntryName.length() > ICON_PATH.length()) {
                        return true;
                    }
                }
            } finally {
                privateZip.close();
            }
        } catch(Exception e) {
            Log.e(TAG, "Could not read zip entries while checking if apk has icon pack", e);
        }
@@ -797,7 +805,6 @@ public class PackageParser {
     * @return True if the asset was successfully processed
     */
    private Map<String, String> getResourceRedirections(String name, String pkg, Resources themeResources, String themePkgName) {
        AssetManager am = themeResources.getAssets();
        if (!name.startsWith("res/"))
            name = "res/" + name;
        if (!name.endsWith(".xml"))