问题描述
请参阅 MSO 问题 一长串可能的重复项——C 内存分配和溢出边界,了解密切相关问题的信息.
Please see MSO question A long list of possible duplicates — C memory allocation and overrunning bounds for information about closely related questions.
开发环境:CentOS 4.7、Kdevelop 3.1.1、gcc 3.4.6
Developer environment: CentOS 4.7, Kdevelop 3.1.1, gcc 3.4.6
我运行一个 Java 测试客户端,它使用 JNI 加载 C++ 共享库.我的应用程序中有三个组件,
I run a Java test client that loads a C++ shared library using JNI. There are three components in my application,
- Java 客户端
- 充当 JNI 包装器的 C++ 共享库.(我称之为wrapperlibrary")
- 包含业务对象的 C++ 共享库.(我称之为商业图书馆")
当我运行客户端时,我经常遇到一个错误,即 *** glibc 检测到 *** free(): invalid next size (fast): 0x080eeef8 ***
.此错误大约出现 10 - 11 次,然后应用程序运行.
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.
在我的 Java 客户端中,我首先在静态构造函数中加载所需的 C++ 库,如下所示,
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");
}
业务库加载"语句被打印在控制台上,但之后出现错误*** glibc...
.
The statement "business library loaded" gets printed on the console but after it the error *** glibc...
comes.
在wrapperlibrary的项目设置中,businesslibrary被指定为依赖库.所以,即使我省略了加载 businesslibrary 的调用而只写了,
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");
}
然后首先加载业务库(通过全局变量创建日志查看),然后加载包装库.控制返回到 java 客户端,并在控制台上打印语句已加载包装器库".在这之后有一个电话到本地方法.但是控件永远不会到达此本机方法的实现.而在此之前,错误 *** glibc...
再次出现.此外,如果我在本地方法调用之前插入对另一个 java 类的静态方法的调用,例如,
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 callto 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;
--
--
}
Try.temp() 的输出永远不会被打印出来.
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?
推荐答案
这可能是因为 Java 本身链接到的 glibc 与您的库不同,或者这些库的链接方式不同/链接到不同的 glibc.
还要检查其中一个库是否链接到 glibc 的调试版本(在 Windows 上使用 C++ 运行时库解决这个问题).尝试将您的库静态链接到 glibc,或者为了排除将您的包装器和业务库静态链接到一个库中的可能性.
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.
这篇关于遇到错误“*** glibc 检测到 *** free(): invalid next size (fast)";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!