求助: 程序运行完成动态内存释放
程序运行完成,在对最后一个动态申请的数组进行释放时出现:corrupted size vs. prev_sizeProgram received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51 ../sysdeps/unix/sysv/linux/raise.c: 没有那个文件或目录.
目前卡在这儿几天了。目前个人揣测是否自己申请的动态内存没有释放完? 还是因为什么。有大佬出现过类似的错误吗?
申请动态数组子函数如下:float complex*** rmall3(int m,int n,int t)
{
int i = 0;
int j = 0;
int k = 0;
float complex*** tt = NULL;
if((m > 0) && (n > 0) && (t > 0))
{
tt = (float complex***)malloc(sizeof(float complex**)*m);
for(i = 0;i < m;i++)
{
tt = (float complex**)malloc(sizeof(float complex*)*n);
for (k = 0;k < n;k++)
{
tt = (float complex*)malloc(sizeof(float complex)*t);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<t;k++)
{
tt=0 + 0*I;
}
}
}
}
return tt;
}
释放动态内存数组的子函数如下:
void fmall3(float complex*** tt,int m,int n)
{
int i;
int j;
for(i = 0;i < m;i++)
{
for (j = 0;j < n;j++)
{
free(tt);
}
}
for(i = 0;i < m;i++)
{
free(tt);
}
free(tt);
// tt = NULL;
}
这是GDB 调试出的信息 BTcorrupted size vs. prev_size
Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51 ../sysdeps/unix/sysv/linux/raise.c: 没有那个文件或目录.
(gdb) bc
Undefined command: "bc".Try "help".
(gdb) bt
#0__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#10x00007ffff7684921 in __GI_abort () at abort.c:79
#20x00007ffff76cd967 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7ffff77fab0d "%s\n")
at ../sysdeps/posix/libc_fatal.c:181
#30x00007ffff76d49da in malloc_printerr (str=str@entry=0x7ffff77f8c1d "corrupted size vs. prev_size") at malloc.c:5342
#40x00007ffff76dc284 in _int_free (have_lock=0, p=<optimized out>, av=0x7ffff7a2fc40 <main_arena>) at malloc.c:4325
#5__GI___libc_free (mem=<optimized out>) at malloc.c:3134
#60x00005555555552f2 in fmall3 (tt=0x5555595f3cc0, m=20, n=20) at srme.c:169
#70x00005555555550fd in main () at srme.c:124
目前情况是,就算我申请的动态内存不释放 程序能正常运行,反而我释放了。。。程序出错了。。可以初步断定是动态内存的问题。。。
页:
[1]