-   Programming (
-   -   *** glibc detected *** free(): invalid next size (

hs_linux 02-26-2010 07:38 AM

*** glibc detected *** free(): invalid next size
(Developer environment: CentOS 4.7, KDevelop 3.1.1, gcc 3.4.5)

I created a c++ shared library and a test executable that uses this shared library. Things work fine.

But when I load this library through Java ie Java calls JNI which in turn loads this shared library, there is an error which states "*** glibc detected *** free(): invalid next size". The application exits after this. This error comes during loading phase of shared library.

Can anyone suggest what might be the possible reason for this?

I am using Java version 1.6.0_17 (build 1.6.0_17-b04). Could there a compatibility issue between this version and the C/C++ runtime libraries?

[Doing rpm -q shows glibc version on my machine as glibc-2.3.4-2.41 and libstdc++ version as libstdc++-3.4.6-10
ldd of shared library shows the following, => /lib/tls/ (0x00173000) => /lib/ (0x00286000) => /usr/lib/ (0x00185000) => /lib/tls/ (0x00111000) => /lib/ (0x00134000) => /lib/tls/ (0x002ba000)
/lib/ (0x008a4000) => /usr/lib/ (0x00785000) => /usr/lib/ (0x003e9000) => /lib/ (0x0013e000) => /usr/lib/ (0x006ae000) => /lib/ (0x00672000) => /lib/ (0x0044e000) => /lib/ (0x00540000) => /usr/lib/ (0x00141000)

paulsm4 02-27-2010 01:08 AM

JNI is a real pain. If you can avoid it, do so.

If you must use JNI, then do this:

1. Code a simple JNI "hello world" first. Do *not* try to implement a full-blown library until you can reliably call C and pass a single value back and forth between Java and C.

2. Make sure you're using C - not C++. All of your C routines should be marked "extern "C" {}".

3. Try to minimize (or better: avoid altogether!) any use of C standard library (or worse, C++ standard library!) functions in your JNI methods.

'Hope that helps .. PSM

Your Java sounds OK.

I presume you're using Sun Java (and not GJC or something like that).

Beware: sometimes alternate Java implementations are installed by default ... you might be calling the wrong JRE and not even know it!

All times are GMT -5. The time now is 09:12 AM.