< prev index next >

src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java

Print this page
rev 57619 : 7143743: (zipfs) Potential memory leak with zip provider
Summary: ZipFileSystem.close() now clears the "inodes" Map, to avoid holding on to potentially large amounts of data
Reviewed-by:


 472         try {
 473             AccessController.doPrivileged((PrivilegedExceptionAction<Void>)() -> {
 474                 sync(); return null;
 475             });
 476             ch.close();              // close the ch just in case no update
 477                                      // and sync didn't close the ch
 478         } catch (PrivilegedActionException e) {
 479             throw (IOException)e.getException();
 480         } finally {
 481             endWrite();
 482         }
 483 
 484         synchronized (inflaters) {
 485             for (Inflater inf : inflaters)
 486                 inf.end();
 487         }
 488         synchronized (deflaters) {
 489             for (Deflater def : deflaters)
 490                 def.end();
 491         }



 492 
 493         IOException ioe = null;
 494         synchronized (tmppaths) {
 495             for (Path p : tmppaths) {
 496                 try {
 497                     AccessController.doPrivileged(
 498                         (PrivilegedExceptionAction<Boolean>)() -> Files.deleteIfExists(p));
 499                 } catch (PrivilegedActionException e) {
 500                     IOException x = (IOException)e.getException();
 501                     if (ioe == null)
 502                         ioe = x;
 503                     else
 504                         ioe.addSuppressed(x);
 505                 }
 506             }
 507         }
 508         provider.removeFileSystem(zfpath, this);
 509         if (ioe != null)
 510            throw ioe;
 511     }




 472         try {
 473             AccessController.doPrivileged((PrivilegedExceptionAction<Void>)() -> {
 474                 sync(); return null;
 475             });
 476             ch.close();              // close the ch just in case no update
 477                                      // and sync didn't close the ch
 478         } catch (PrivilegedActionException e) {
 479             throw (IOException)e.getException();
 480         } finally {
 481             endWrite();
 482         }
 483 
 484         synchronized (inflaters) {
 485             for (Inflater inf : inflaters)
 486                 inf.end();
 487         }
 488         synchronized (deflaters) {
 489             for (Deflater def : deflaters)
 490                 def.end();
 491         }
 492         // clear the inodes since they can potentially hold on to large amounts
 493         // of data (especially IndexNode of type ZipFileSystem$Entry)
 494         inodes.clear();
 495 
 496         IOException ioe = null;
 497         synchronized (tmppaths) {
 498             for (Path p : tmppaths) {
 499                 try {
 500                     AccessController.doPrivileged(
 501                         (PrivilegedExceptionAction<Boolean>)() -> Files.deleteIfExists(p));
 502                 } catch (PrivilegedActionException e) {
 503                     IOException x = (IOException)e.getException();
 504                     if (ioe == null)
 505                         ioe = x;
 506                     else
 507                         ioe.addSuppressed(x);
 508                 }
 509             }
 510         }
 511         provider.removeFileSystem(zfpath, this);
 512         if (ioe != null)
 513            throw ioe;
 514     }


< prev index next >