Changeset 7c7b0cb for core


Ignore:
Timestamp:
Apr 8, 2019 3:37:20 PM (14 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
488e89a
Parents:
6aeb89c
Message:

Util: Fix memory leak in compressor (ticket #2471)

Location:
core/java/src/net/i2p/util
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/util/ResettableGZIPInputStream.java

    r6aeb89c r7c7b0cb  
    167167            return true;
    168168        }
     169    }
     170
     171    /**
     172     *  Calls super.close(). May not be reused after this.
     173     *  @since 0.9.40
     174     */
     175    public void destroy() throws IOException {
     176        close();
     177        super.close();
    169178    }
    170179
  • core/java/src/net/i2p/util/ResettableGZIPOutputStream.java

    r6aeb89c r7c7b0cb  
    1919    /** has the header been written out yet? */
    2020    private boolean _headerWritten;
     21    private boolean _footerWritten;
    2122    /** how much data is in the uncompressed stream? */
    2223    private long _writtenSize;
     
    4041        _writtenSize = 0;
    4142        _headerWritten = false;
     43        _footerWritten = false;
    4244    }
    4345   
     
    6264   
    6365    private void writeFooter() throws IOException {
     66        if (_footerWritten) return;
    6467        // damn RFC writing their bytes backwards...
    6568        long crcVal = _crc32.getValue();
     
    8487            System.out.println();
    8588        }
     89        _footerWritten = true;
     90    }
     91
     92    /**
     93     *  Calls super.close(). May not be reused after this.
     94     *  @since 0.9.40
     95     */
     96    public void destroy() throws IOException {
     97        def.end();
     98        super.close();
    8699    }
    87100   
     
    91104        super.close();
    92105    }
     106
    93107    @Override
    94108    public void finish() throws IOException {
     
    105119        super.write(b);
    106120    }
     121
    107122    @Override
    108123    public void write(byte buf[]) throws IOException {
    109124        write(buf, 0, buf.length);
    110125    }
     126
    111127    @Override
    112128    public void write(byte buf[], int off, int len) throws IOException {
  • core/java/src/net/i2p/util/ReusableGZIPInputStream.java

    r6aeb89c r7c7b0cb  
    11package net.i2p.util;
    22
     3import java.io.IOException;
    34import java.util.concurrent.LinkedBlockingQueue;
    45
     
    3334        return rv;
    3435    }
     36
    3537    /**
    3638     * Release an instance back into the cache (this will reset the
     
    3840     */
    3941    public static void release(ReusableGZIPInputStream released) {
    40         if (ENABLE_CACHING)
    41             _available.offer(released);
     42        boolean cached;
     43        if (ENABLE_CACHING) {
     44            cached = _available.offer(released);
     45        } else {
     46            cached = false;
     47        }
     48        if (!cached) {
     49            try { released.destroy(); } catch (IOException ioe) {}
     50        }
    4251    }
    4352   
  • core/java/src/net/i2p/util/ReusableGZIPOutputStream.java

    r6aeb89c r7c7b0cb  
    33//import java.io.ByteArrayInputStream;
    44import java.io.ByteArrayOutputStream;
     5import java.io.IOException;
    56import java.util.zip.Deflater;
    67import java.util.concurrent.LinkedBlockingQueue;
     
    5152     */
    5253    public static void release(ReusableGZIPOutputStream out) {
    53         out.reset();
    54         if (ENABLE_CACHING)
    55             _available.offer(out);
     54        boolean cached;
     55        if (ENABLE_CACHING) {
     56            out.reset();
     57            cached = _available.offer(out);
     58        } else {
     59            cached = false;
     60        }
     61        if (!cached) {
     62            try { out.destroy(); } catch (IOException ioe) {}
     63        }
    5664    }
    5765   
Note: See TracChangeset for help on using the changeset viewer.