zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maoling <...@git.apache.org>
Subject [GitHub] zookeeper pull request #356: ZOOKEEPER-2572: Fix potential resource leak in ...
Date Mon, 04 Sep 2017 01:17:32 GMT
Github user maoling commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/356#discussion_r136731827
  
    --- Diff: src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java ---
    @@ -399,18 +403,20 @@ public boolean truncate(long zxid) throws IOException {
                 }
                 long pos = input.getPosition();
                 // now, truncate at the current position
    -            RandomAccessFile raf=new RandomAccessFile(itr.logFile,"rw");
    +            raf = new RandomAccessFile(itr.logFile, "rw");
                 raf.setLength(pos);
    -            raf.close();
                 while(itr.goToNextLog()) {
    -                if (!itr.logFile.delete()) {
    -                    LOG.warn("Unable to truncate {}", itr.logFile);
    +                try {
    +                    Files.delete(itr.logFile.toPath());
    +                } catch (NoSuchFileException e) {
                     }
                 }
             } finally {
                 close(itr);
    +            if (raf != null) {
    +                raf.close();
    +            }
             }
    -        return true;
         }
    --- End diff --
    
    IMHO.should we put code block `Line416-Line418 ` before ` Line415` ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message