简体   繁体   English

malloc:对象的错误:未分配被释放的指针

[英]malloc: error for object: pointer being freed was not allocated

so I made a JNI wrapper for an MSER in OpenCv v2.4.13.2. 所以我在OpenCv v2.4.13.2中为MSER创建了一个JNI包装器。

I receive this error after about 5 minutes leaving the Java process running: 离开Java进程运行大约5分钟后,我收到此错误:

java(658,0x7000070bb000) malloc: *** error for object 0x11921c6f0: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug

This is most definitely from the use of JNI, but I'm unsure of what exactly is causing this malloc error as I am not terribly familiar with C++. 这绝对是使用JNI,但我不确定究竟是什么导致了这个malloc错误,因为我对C ++并不十分熟悉。 I'm guessing it's due to improper memory clearing, but am unsure of where. 我猜这是由于内存清除不当,但我不确定在哪里。

Relevant code from my file: 我文件中的相关代码:

MSER mser; // Global variable so that pointer useable by Java can be created

JNIEXPORT jlong JNICALL Java_org_opencv_features2d_MSER_create_11(JNIEnv* env, jclass cls, jint delta, jint min_area, jint max_area, jdouble max_variation, jdouble min_diversity, jint max_evolution, jdouble area_threshold, jdouble min_margin, jint edge_blur_size)
{
    static const char method_name[] = "MSSR::create_1";

    //LOGD("%s", method_name);

    mser = MSER::MSER(delta, min_area, max_area, max_variation, min_diversity, max_evolution, area_threshold, min_margin, edge_blur_size);

    return (jlong) &mser;
}

JNIEXPORT void JNICALL Java_org_opencv_features2d_MSER_detect_14(JNIEnv* env, jobject thiz, jlong self, jlong image_addr, jlong msers_addr, jlong mask_addr)
{
    static const char method_name[] = "MSSR::detect_4";

    try {
        //LOGD("%s", method_name);
        MSER* me = (MSER*) self;
        Mat image = *(Mat*) image_addr;
        vector<vector<Point> > msers; // List<MatOfPoint> -> Mat -> vector<vector<Point> >
        Mat mask = *(Mat*) mask_addr;
        me->operator()(image, msers, mask);
        vector_vector_Point_to_Mat(msers, *(Mat*)msers_addr); // Store vector data in Mat dummy to be converted to List<MatOfPoint>
    }
    catch (const exception &e) {
        throwJavaException(env, &e, method_name);
    }
    catch (...) {
        throwJavaException(env, 0, method_name);
    }
}

And from converters.cpp: 来自converters.cpp:

#define CHECK_MAT(cond) if(!(cond)){ return; }

void vector_vector_Point_to_Mat(std::vector< std::vector< Point > >& vv_pt, Mat& mat)
{
    std::vector<Mat> vm;
    vm.reserve( vv_pt.size() );
    for(size_t i=0; i<vv_pt.size(); i++)
    {
        Mat m;
        vector_Point_to_Mat(vv_pt[i], m);
        vm.push_back(m);
    }
    vector_Mat_to_Mat(vm, mat);
}

void vector_Mat_to_Mat(std::vector<cv::Mat>& v_mat, cv::Mat& mat)
{
    int count = (int)v_mat.size();
    mat.create(count, 1, CV_32SC2);
    for(int i=0; i<count; i++)
    {
        long long addr = (long long) new Mat(v_mat[i]);
        mat.at< Vec<int, 2> >(i, 0) = Vec<int, 2>(addr>>32, addr&0xffffffff);
    }
}

This also only seems to happen when I have multiple instances of the same program running. 当我运行同一程序的多个实例时,这似乎也只会发生。 That probably means it has something to do with the global MSER mser variable. 这可能意味着它与全局MSER mser变量有关。

Thanks in advance, 提前致谢,
Kira 基拉

Try to use gdb and check the back trace inside: 尝试使用gdb并检查里面的后跟踪:

malloc_error_break malloc_error_break

You can find information on how to debug JNI + Java here: 您可以在此处找到有关如何调试JNI + Java的信息:

http://jnicookbook.owsiak.org/recipe-No-D001/ http://jnicookbook.owsiak.org/recipe-No-D001/

http://jnicookbook.owsiak.org/recipe-No-D002/ http://jnicookbook.owsiak.org/recipe-No-D002/

You can also take a look at demo movie here: 您还可以在这里看看演示电影:

https://youtu.be/8Cjeq4l5COU https://youtu.be/8Cjeq4l5COU

In case you can't use CLion and you have to stick to gdb, take a look here on how to debug Java + native code: 如果你不能使用CLion而你必须坚持使用gdb,请看一下如何调试Java +本机代码:

http://www.owsiak.org/?p=2095 http://www.owsiak.org/?p=2095

Basically, what you can do is to: 基本上,你可以做的是:

  • start JVM in debug mode 在调试模式下启动JVM
  • attach to JVM using gdb 使用gdb附加到JVM
  • inside gdb set breakpoint to: malloc_error_break 在gdb里面设置断点为:malloc_error_break

break malloc_error_break

  • once breakpoint is hit, take a look at back trace and see what was called just before malloc_error_break was hit 一旦断点被​​击中,看看后面的跟踪,看看在malloc_error_break被击中之前调用了什么

Have fun with JNI! 与JNI玩得开心!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 malloc:***对象错误:未分配要释放的指针 - malloc: *** error for object: pointer being freed was not allocated malloc:***对象0x00的错误:未分配释放的指针 - malloc: *** error for object 0x00: pointer being freed was not allocated malloc:***对象的错误:没有分配被释放的指针***在malloc_error_break中设置一个断点来调试 - malloc: *** error for object: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug 仅在模拟器中出现“未分配释放的malloc错误指针”错误: - “ malloc error pointer being freed was not allocated ” error only in simulator: C++ 错误:如何解决 malloc:对象的 *** 错误...被释放的指针未分配 - C++ error: How to solve malloc: *** error for object ... pointer being freed was not allocated 错误:malloc:*** object 0x7f9edf504080 的错误:未分配被释放的指针 - Error: malloc: *** error for object 0x7f9edf504080: pointer being freed was not allocated 具有Qt的C ++应用程序中的IImebra代码给出了malloc:***对象xxxxxx的错误:未分配要释放的指针 - IImebra code in C++ app with Qt gives malloc: *** error for object xxxxxx: pointer being freed was not allocated malloc:***对象0x7fff5fbff350的错误:释放的指针未分配 - malloc: *** error for object 0x7fff5fbff350: pointer being freed was not allocated malloc:对象0x1029249b0的错误:未分配要释放的指针 - malloc: *** error for object 0x1029249b0: pointer being freed was not allocated malloc:***对象0x10020a2c0错误:未分配释放的指针***在malloc_error_break中设置一个断点进行调试 - malloc: *** error for object 0x10020a2c0: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM