Changeset 18770 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2023-06-23T15:01:21+02:00 (17 months ago)
Author:
taylor.smock
Message:

Fix a potential resource leak (CID-1349914)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r18011 r18770  
    210210            return new ByteArrayInputStream(css.getBytes(StandardCharsets.UTF_8));
    211211        }
    212         CachedFile cf = getCachedFile();
    213         if (isZip) {
    214             File file = cf.getFile();
    215             zipFile = new ZipFile(file, StandardCharsets.UTF_8);
    216             zipIcons = file;
    217             I18n.addTexts(zipIcons);
    218             ZipEntry zipEntry = zipFile.getEntry(zipEntryPath);
    219             return zipFile.getInputStream(zipEntry);
    220         } else {
    221             zipFile = null;
    222             zipIcons = null;
    223             return cf.getInputStream();
     212        // This just closes any open http connections. It does not (with the current CachedFile implementation) close
     213        // streams that it provides via getInputStream.
     214        try (CachedFile cf = getCachedFile()) {
     215            if (isZip) {
     216                File file = cf.getFile();
     217                zipFile = new ZipFile(file, StandardCharsets.UTF_8);
     218                zipIcons = file;
     219                I18n.addTexts(zipIcons);
     220                ZipEntry zipEntry = zipFile.getEntry(zipEntryPath);
     221                return zipFile.getInputStream(zipEntry);
     222            } else {
     223                zipFile = null;
     224                zipIcons = null;
     225                return cf.getInputStream();
     226            }
    224227        }
    225228    }
Note: See TracChangeset for help on using the changeset viewer.