免费的():上FCLOSE无效的下一个大小(正常)。而不是在Valgrind的运行 [英] free(): invalid next size (normal) on fclose. But not when Valgrind runs

查看:250
本文介绍了免费的():上FCLOSE无效的下一个大小(正常)。而不是在Valgrind的运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在code以下的 FCLOSE()通话中断。

 无效output_gauss_transform(字符*文件名,字符*模式,双** T,
                            双转移,INT LEN)
{
    FILE * FP;    的printf(1.4.3高斯变换到%s \\ n,文件名);    如果((FP = FOPEN(文件名,模式))== NULL){
    PERROR(无法打开文件);
    返回;
    }    INT I;    对于(i = 0; I< LEN ++我){
    fprintf中(FP,LF%LF%\\ n,T [0] [I],T [1] [I] +移);
    }    如果(FCLOSE(FP)){
    的printf(错误关闭\\ n);
    }
}

的glibc 给我这个错误,与存储器映射一起。

  *** glibc的检测*** [sourcedir] /库/ LT-发射:免费():无效的下一个尺寸(标准):0x0821da38 ***
=======回溯:=========
/lib/i386-linux-gnu/libc.so.6(+0x75ee2)[0xb739dee2]
/lib/i386-linux-gnu/libc.so.6(fclose+0x154)[0xb738d424]
/src/.libs/libfile_util.so.0(output_gauss_transform+0xa9)[0xb77b5859]
/src/.libs/lt-launcher[0x804a0f9]
/src/.libs/lt-launcher[0x804a2a5]
/src/.libs/lt-launcher[0x804983b]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0xb73414d3]
/src/.libs/lt-launcher[0x8049915]

在尝试与的valgrind 来调试这个,我没有得到任何错误,标明其输出以下。到底是怎么回事?

  == == 30396 HEAP摘要:
== == 30396在退出,使用:0块0字节
== == 30396总堆的使用情况:1,059 allocs,1,059的FreeS,78149字节分配
== == 30396
== == 30396所有堆块被释放 - 无泄漏是可能的
== == 30396
== == 30396侦测到并SUP pressed错误计数,重新运行:-v
== == 30396错误摘要:从0 0上下文错误(SUP pressed:0 0)

编辑:运行的valgrind -v ,我得到在结束这件事。也许它是与正在发生的事情?

  --31325-- REDIR:0x454cac0(delete操作符(无效*))重定向到0x402bb98(delete操作符(无效*))


解决方案

这code是的受害者的,你需要找到肇事者。当你调用 FCLOSE ,部分结构被释放。在这一点上,code发现空闲池已损坏并报告错误。但是,它是破坏了免费使用游泳池,code的其他一些大块不是这个code。

此错误的最常见的原因是两次释放相同的内存块和访问的内存块你已经释放之后。这是奇怪的是,的valgrind 没能赶上这一点,因为这是完全错误类型通常捕获。

The code below breaks on the fclose() call.

void output_gauss_transform(char* filename, char* mode, double** T, 
                            double shift, int len)
{
    FILE* fp;

    printf("Outputting gauss transform to %s.\n", filename);

    if ((fp = fopen(filename, mode)) == NULL){
    perror("Could not open file");
    return;
    }

    int i;

    for (i = 0; i < len; ++i) {
    fprintf(fp, "%lf %lf\n", T[0][i], T[1][i] + shift);
    }

    if (fclose(fp)){
    printf("error closing\n");
    }
}

glibc gives me this error, along with the memory map.

*** glibc detected *** [sourcedir]/.libs/lt-launcher: free(): invalid next size (normal): 0x0821da38 ***
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(+0x75ee2)[0xb739dee2]
/lib/i386-linux-gnu/libc.so.6(fclose+0x154)[0xb738d424]
/src/.libs/libfile_util.so.0(output_gauss_transform+0xa9)[0xb77b5859]
/src/.libs/lt-launcher[0x804a0f9]
/src/.libs/lt-launcher[0x804a2a5]
/src/.libs/lt-launcher[0x804983b]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0xb73414d3]
/src/.libs/lt-launcher[0x8049915]

When attempting to debug this with valgrind, I get no errors whatsoever, with it outputting the following. What is going on?

==30396== HEAP SUMMARY:
==30396==     in use at exit: 0 bytes in 0 blocks
==30396==   total heap usage: 1,059 allocs, 1,059 frees, 78,149 bytes allocated
==30396== 
==30396== All heap blocks were freed -- no leaks are possible
==30396== 
==30396== For counts of detected and suppressed errors, rerun with: -v
==30396== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

edit: Running valgrind with -v, I get this thing at the end. Perhaps it has something to do with what is going on?

 --31325-- REDIR: 0x454cac0 (operator delete(void*)) redirected to 0x402bb98 (operator delete(void*))

解决方案

This code is the victim, you need to find the perpetrator. When you call fclose, some structure is freed. At that point, the code discovers that the free pool is corrupt and reports an error. However, it's some other chunk of code that corrupted the free pool, not this code.

The most common causes of this error are freeing the same block of memory twice and accessing a block of memory after you've freed it. It's strange that valgrind wasn't able to catch this, since these are exactly the kind of errors it usually catches.

这篇关于免费的():上FCLOSE无效的下一个大小(正常)。而不是在Valgrind的运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆