具有无效堆地址和致命信号的Android JNI 11

时间:2014-01-24 16:27:03

标签: java android c++ java-native-interface heap

我现在通过JNI将一个C ++项目转移到android。

当我进行两次操作时,就像下面的代码一样,

项目会崩溃并显示日志

  

@@@ ABORTING:dlfree addr中的无效地址= 0x2a152f58

     

致命信号11(SIGSEGV)位于0xdeadbaad(代码= 1),线程18576

        for (size_t i=0; i<n_matching_pairs; i++)
      {
        /* read descriptors: */
        ......

        unsigned char *q_dsc, *r_dsc;
        q_dsc = new unsigned char [MAX_DSC_LENGTH];
        r_dsc = new unsigned char [MAX_DSC_LENGTH];

        if ((q_file = fopen (q_fname.c_str(), "rb")) == NULL)
        {
            traceMgr.start("no q_file");
        }
        if ((q_dsc_len = (int)fread (q_dsc, 1,MAX_DSC_LENGTH, q_file)) <= 0)
        {
            traceMgr.start("no qdsc_file");
        }
        __android_log_print(ANDROID_LOG_INFO, "JNIMsg2","Q:  %d , %p ", q_dsc_len,&q_dsc);
        fclose (q_file);

        if ((r_file = fopen (r_fname.c_str(), "rb")) == NULL)
        {
            traceMgr.start("no r_file");
        }
        if ((r_dsc_len = (int)fread (r_dsc, 1, MAX_DSC_LENGTH, r_file)) <= 0)
        {
            traceMgr.start("no rdsc_file");
        }
         __android_log_print(ANDROID_LOG_INFO, "JNIMsg1","R: %d , %p", r_dsc_len,&r_dsc);
        fclose (r_file);
        .....

我试图打印我得到的fread指针的地址

  

01-24 16:13:46.791:I / JNIMsg2(18576):问:1020,0xbe85ead8

     

01-24 16:13:46.791:I / JNIMsg1(18576):R:991,0xbe85eadc

与无效堆非常不同。

此外,我尝试只在下面的for循环中进行一次fread,然后就没有崩溃了

        for (size_t i=0; i<n_matching_pairs; i++)
      {
        /* read descriptors: */
        ......

        unsigned char *q_dsc, *r_dsc;
        q_dsc = new unsigned char [MAX_DSC_LENGTH];
        r_dsc = new unsigned char [MAX_DSC_LENGTH];

        if ((q_file = fopen (q_fname.c_str(), "rb")) == NULL)
        {
            traceMgr.start("no q_file");
        }
        if ((q_dsc_len = (int)fread (q_dsc, 1,MAX_DSC_LENGTH, q_file)) <= 0)
        {
            traceMgr.start("no qdsc_file");
        }
        __android_log_print(ANDROID_LOG_INFO, "JNIMsg2","Q:  %d , %p ", q_dsc_len,&q_dsc);
        fclose (q_file);
                ....

或者像这样减小文件读取范围的大小,也不会崩溃

(MAX_DSC_LENGTH = 1024 * 32 - &gt;将此值减少到100会起作用,但200会再次崩溃....)

        for (size_t i=0; i<n_matching_pairs; i++)
      {
        /* read descriptors: */
        ......

        unsigned char *q_dsc, *r_dsc;
        q_dsc = new unsigned char [MAX_DSC_LENGTH];
        r_dsc = new unsigned char [MAX_DSC_LENGTH];

        if ((q_file = fopen (q_fname.c_str(), "rb")) == NULL)
        {
            traceMgr.start("no q_file");
        }
        if ((q_dsc_len = (int)fread (q_dsc, 1,100, q_file)) <= 0)
        {
            traceMgr.start("no qdsc_file");
        }
        __android_log_print(ANDROID_LOG_INFO, "JNIMsg2","Q:  %d , %p ", q_dsc_len,&q_dsc);
        fclose (q_file);

        if ((r_file = fopen (r_fname.c_str(), "rb")) == NULL)
        {
            traceMgr.start("no r_file");
        }
        if ((r_dsc_len = (int)fread (r_dsc, 1, 100, r_file)) <= 0)
        {
            traceMgr.start("no rdsc_file");
        }
         __android_log_print(ANDROID_LOG_INFO, "JNIMsg1","R: %d , %p", r_dsc_len,&r_dsc);
        fclose (r_file);
        .....

有人能为我提供解决问题的方向吗?

0 个答案:

没有答案