请参阅MSO问题可能重复的长列表 - C内存分配和超限界限,以获取有关密切相关问题的信息.
开发人员环境:CentOS 4.7,Kdevelop 3.1.1,gcc 3.4.6
我运行一个Java测试客户端,使用JNI加载C++共享库.我的应用程序有三个组件,
当我运行客户端时,我经常遇到错误,即*** glibc detected *** free(): invalid next size (fast): 0x080eeef8 ***.此错误大约10到11次,然后应用程序运行.
在我的Java客户端中,我首先在静态ctor中加载所需的C++库,如下所示,
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");
}
Run Code Online (Sandbox Code Playgroud)
"业务库已加载"语句将打印在控制台上,但之后会出现错误*** glibc....
在wrapperlibrary的项目设置中,businesslibrary被指定为依赖库.所以,即使我省略了加载businesslibrary并且只是写的调用,
static
{
System.Load("/root/Desktop/libs/wrapperlibrary");
System.out.println("wrapper library loaded");
}
Run Code Online (Sandbox Code Playgroud)
然后首先加载businesslibrary(通过全局变量创建日志记录看到),然后加载wrapperlibrary.控件返回到java客户端,并在控制台上打印语句"wrapper library loaded".在此之后,调用本机方法.但控件永远不会达到这种本机方法的实现.而在此之前,错误*** glibc...再次出现.另外如果我在本机方法调用之前插入对另一个java类的静态方法的调用,例如,
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;
-- …Run Code Online (Sandbox Code Playgroud) 我遇到了realloc函数的问题.我只使用C(因此没有向量)与LibCurl.我遇到的问题是我在write_data函数的第12次迭代中得到以下错误(realloc():无效的下一个大小)(我将函数作为回调传递给Curl,每次libcurl都调用它时一些要传回的数据(数据以块的形式传递)).
-Removed-
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
#include <string.h>
char * Data; //stores the data
size_t RunningSize;
int write_data( char *ptr, size_t size, size_t nmemb, void *stream )
{
size_t ThisSize = (size * nmemb); //Stores the size of the data to be stored
size_t DataLen = strlen( Data ); //length of the data so far
RunningSize = (RunningSize + ThisSize ); //update running size (used as new size)
Data = realloc( Data, RunningSize ); //get new …Run Code Online (Sandbox Code Playgroud) 我已经阅读了这种类型的其他问题,但我仍然无法弄清楚为什么在我的代码中发生了这个错误.
这是我的代码:
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int len;
int str[0];
} bit_str;
bit_str * input(void);
void print_bitstr(bit_str * s);
int main(void)
{
bit_str * s1 = input();
print_bitstr(s1);
return 0;
}
bit_str * input(void)
{
bit_str *s = (bit_str *) malloc(sizeof(bit_str));
int count = 0, bit;
while ((bit = getchar()) != 'k'){
s = (bit_str *) realloc(s, sizeof(*s) + sizeof(int));
s->str[count++] = bit - 48;
}
s->len = count;
return s;
}
void print_bitstr(bit_str * s)
{ …Run Code Online (Sandbox Code Playgroud)