-
-
Notifications
You must be signed in to change notification settings - Fork 591
Description
Here's a minimal repro. I'm seeing this with javacpp and javacpp-presets 1.5.4, with only the 8 jars javacpp{-platform,-windows-x86,-windows-x86_64,,}.jar and fftw{-platform,-windows-x86,-windows-x86_64,,}.jar on the classpath.
public class Main {
public static void main(String[] args) {
Loader.load(org.bytedeco.fftw.global.fftw3.class);
Pointer data1 = Pointer.malloc(10);
System.out.printf("data1:0x%08xd\n", data1.address());
Pointer.free(data1);
BytePointer data2 = fftw_export_wisdom_to_string();
System.out.printf("data2:0x%08xd\n", data2.address());
Pointer.free(data2); // Crashes here
}
}
This produces:
data1:0x1f126290d
data2:0x00284500d
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000007712a407, pid=17116, tid=0x0000000000002b0c
#
# JRE version: Java(TM) SE Runtime Environment (8.0_261-b12) (build 1.8.0_261-b12)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.261-b12 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [ntdll.dll+0x2a407]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\D\eclipse-workspace-gl\crash-repro\hs_err_pid17116.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
As you can see, the two pointers have very different address ranges, which shows that they're being allocated from different heaps. (Which explains why free()'ing crashes.) fftw_export_wisdom_to_string() is documented as returning memory that needs to be free'd, see here: http://www.fftw.org/fftw3_doc/Wisdom-Export.html. And you can clearly see in the code that they're using plain malloc() for the result: https://github.com/FFTW/fftw3/blob/master/api/export-wisdom-to-string.c
So, how do I get access (from Java) to the free() that corresponds to the malloc() that fftw is linking against?