< 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         beginWrite(); // lock and sync
 493         try {
 494             // clear the inodes since they can potentially hold on to large amounts
 495             // of data (especially IndexNode of type ZipFileSystem$Entry)
 496             inodes.clear();
 497         } finally {
 498             endWrite();
 499         }
 500 
 501         IOException ioe = null;
 502         synchronized (tmppaths) {
 503             for (Path p : tmppaths) {
 504                 try {
 505                     AccessController.doPrivileged(
 506                         (PrivilegedExceptionAction<Boolean>)() -> Files.deleteIfExists(p));
 507                 } catch (PrivilegedActionException e) {
 508                     IOException x = (IOException)e.getException();
 509                     if (ioe == null)
 510                         ioe = x;
 511                     else
 512                         ioe.addSuppressed(x);
 513                 }
 514             }
 515         }
 516         provider.removeFileSystem(zfpath, this);
 517         if (ioe != null)
 518            throw ioe;
 519     }


< prev index next >