Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

linux - Facing an error "*** glibc detected *** free(): invalid next size (fast)"

Please see MSO question A long list of possible duplicates —?C memory allocation and overrunning bounds for information about closely related questions.


Developer environment: CentOS 4.7, Kdevelop 3.1.1, gcc 3.4.6

I run a Java test client that loads a C++ shared library using JNI. There are three components in my application,

  1. Java client
  2. C++ shared library which acts as a JNI wrapper. (I will call it "wrapperlibrary")
  3. C++ shared library containing business objects. (I will call it "businesslibrary")

When I run the client I face an error very frequently which is, *** glibc detected *** free(): invalid next size (fast): 0x080eeef8 ***. This error comes for around 10 - 11 times and then the application runs.

In my Java client, I first load the required C++ libraries in a static ctor as follows,

static
{
System.Load("/root/Desktop/libs/businesslibrary");
System.out.println("business library loaded");
System.Load("/root/Desktop/libs/wrapperlibrary");
System.out.println("wrapper library loaded");
}

The statement "business library loaded" gets printed on the console but after it the error *** glibc... comes.

In the project settings of wrapperlibrary, the businesslibrary is specified as a dependant library. So, even if I omit the call to load businesslibrary and just write,

static
{
System.Load("/root/Desktop/libs/wrapperlibrary");
System.out.println("wrapper library loaded");
}

then firstly the businesslibrary gets loaded(seen through global variable creation logging) and then the wrapperlibrary gets loaded. The control returns back to java client and the statement "wrapper library loaded" is printed on console. After this there is a call to native method. But the control never reaches this native method's implementation. Rather before that the error *** glibc... again comes. Also if I insert a call to static method of another java class before native method call such as,

static
{
 System.Load("/root/Desktop/libs/wrapperlibrary");
 System.out.println("wrapper library loaded");
 System.out.println(Try.temp()); //where temp is a static method of Try class which returns a string.

 native method call;

 --
 --
}

then output of Try.temp() never gets printed.

What could be the possible reasons for the problem in both these approaches and how should I proceed?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It could be that Java itself is linked against a different glibc than your libraries or that the libraries are linked differently/to different glibcs.
Also check if one of the libraries is linking against a debug version of the glibc (hat that problem on windows with the C++ runtime lib). Try linking your libraries staticly against the glibc, or for the sake of excluding possibilities linking your wrapper and business libs staticly into one library.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...