[ 
https://issues.apache.org/jira/browse/HADOOP-11526?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Anu Engineer updated HADOOP-11526:
----------------------------------
    Attachment: HADOOP-11526.002.patch

Thanks for catching this Chris. I also read thru the rest of code in that 
directory and it looks we have one more memory leak. I have fixed it in the 
code. I confirmed the leak by writing a sample program and then running it 
under valgrind.

Here is my test program:
#include <bzlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void main()
{
        bz_stream *stream = (bz_stream *) malloc(sizeof(bz_stream));
        memset((void *)stream, 0, sizeof(bz_stream));
        BZ2_bzCompressInit(stream,9,0,0);
        BZ2_bzCompressEnd(stream);
        
}

if I run this run under valgrind, then valgrind complains about 80 bytes which 
are missing. The stream that we alloc has to be freed. That fix is also in this 
change.



> Memory leak in Bzip2Decompressor
> --------------------------------
>
>                 Key: HADOOP-11526
>                 URL: https://issues.apache.org/jira/browse/HADOOP-11526
>             Project: Hadoop Common
>          Issue Type: Bug
>          Components: io, native
>    Affects Versions: 2.6.0
>            Reporter: Ian Rogers
>            Assignee: Anu Engineer
>         Attachments: HADOOP-11526.001.patch, HADOOP-11526.002.patch
>
>
> The use of JNI's GetStringUTFChars should be paired with 
> ReleaseStringUTFChars or else the utf-8 char* created by Java's JNI 
> implementation is leaked. It isn't in Bzip2Decompressor.c:
> https://apache.googlesource.com/hadoop-common/+/refs/heads/trunk/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/compress/bzip2/Bzip2Decompressor.c#45
> A less error-prone way of handling JNI resources like local references and 
> UTF strings is to use a smart pointer like the Apache licensed code in 
> Android's ScopedLocalRef and ScopedUtfChars:
> https://android.googlesource.com/platform/libnativehelper/+/jb-mr1.1-dev-plus-aosp/include/nativehelper/ScopedLocalRef.h
> https://android.googlesource.com/platform/libnativehelper/+/jb-mr1.1-dev-plus-aosp/include/nativehelper/ScopedUtfChars.h



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to