LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-26-2010, 07:38 AM   #1
hs_linux
LQ Newbie
 
Registered: Dec 2009
Posts: 14

Rep: Reputation: 0
*** 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,
libpthread.so.0 => /lib/tls/libpthread.so.0 (0x00173000)
libssl.so.4 => /lib/libssl.so.4 (0x00286000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00185000)
libm.so.6 => /lib/tls/libm.so.6 (0x00111000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00134000)
libc.so.6 => /lib/tls/libc.so.6 (0x002ba000)
/lib/ld-linux.so.2 (0x008a4000)
libgssapi_krb5.so.2 => /usr/lib/libgssapi_krb5.so.2 (0x00785000)
libkrb5.so.3 => /usr/lib/libkrb5.so.3 (0x003e9000)
libcom_err.so.2 => /lib/libcom_err.so.2 (0x0013e000)
libk5crypto.so.3 => /usr/lib/libk5crypto.so.3 (0x006ae000)
libresolv.so.2 => /lib/libresolv.so.2 (0x00672000)
libcrypto.so.4 => /lib/libcrypto.so.4 (0x0044e000)
libdl.so.2 => /lib/libdl.so.2 (0x00540000)
libz.so.1 => /usr/lib/libz.so.1 (0x00141000)
]
 
Old 02-27-2010, 01:08 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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

PS:
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!
 
  


Reply

Tags
c++, centos, java, linux



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting *** glibc detected *** free(): invalid next size (normal): herat.acharya Programming 3 10-23-2009 03:50 AM
*** glibc detected *** free(): invalid next size (normal): 0x0000000000503e70 *** vbreddy Programming 2 04-10-2006 06:27 PM
*** glibc detected *** free(): invalid next size (normal): 0x0804c050 *** water&sky Linux - General 2 03-03-2006 12:25 PM
*** glibc detected *** free(): invalid next size (normal): 0x0804c050 *** water&sky Linux - Software 1 03-02-2006 08:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration