新手,一个简单的程序问题。
时间:2011-11-26
来源:互联网
C/C++ code
出错:
*** glibc detected *** ./write: double free or corruption (top): 0x081c0008 ***
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(+0x6ebc2)[0x68cbc2]
/lib/i386-linux-gnu/libc.so.6(+0x6f862)[0x68d862]
/lib/i386-linux-gnu/libc.so.6(cfree+0x6d)[0x69094d]
/lib/i386-linux-gnu/libc.so.6(fclose+0x154)[0x67c0b4]
./write[0x8048706]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0x637113]
./write[0x8048501]
======= Memory map: ========
0061e000-00794000 r-xp 00000000 08:01 394150 /lib/i386-linux-gnu/libc-2.13.so
00794000-00796000 r--p 00176000 08:01 394150 /lib/i386-linux-gnu/libc-2.13.so
00796000-00797000 rw-p 00178000 08:01 394150 /lib/i386-linux-gnu/libc-2.13.so
00797000-0079a000 rw-p 00000000 00:00 0
007ee000-007ef000 r-xp 00000000 00:00 0 [vdso]
00ad7000-00af3000 r-xp 00000000 08:01 394171 /lib/i386-linux-gnu/libgcc_s.so.1
00af3000-00af4000 r--p 0001b000 08:01 394171 /lib/i386-linux-gnu/libgcc_s.so.1
00af4000-00af5000 rw-p 0001c000 08:01 394171 /lib/i386-linux-gnu/libgcc_s.so.1
00fca000-00fe8000 r-xp 00000000 08:01 394137 /lib/i386-linux-gnu/ld-2.13.so
00fe8000-00fe9000 r--p 0001d000 08:01 394137 /lib/i386-linux-gnu/ld-2.13.so
00fe9000-00fea000 rw-p 0001e000 08:01 394137 /lib/i386-linux-gnu/ld-2.13.so
08048000-08049000 r-xp 00000000 08:01 416755 /home/zhayun/write
08049000-0804a000 r--p 00000000 08:01 416755 /home/zhayun/write
0804a000-0804b000 rw-p 00001000 08:01 416755 /home/zhayun/write
081c0000-081e1000 rw-p 00000000 00:00 0 [heap]
b7600000-b7621000 rw-p 00000000 00:00 0
b7621000-b7700000 ---p 00000000 00:00 0
b778c000-b778d000 rw-p 00000000 00:00 0
b779a000-b779e000 rw-p 00000000 00:00 0
bf8be000-bf8df000 rw-p 00000000 00:00 0 [stack]
已放弃
gdb 调试提示:Program received signal SIGABRT, Aborted.
#include<stdio.h> FILE *stream,*fp; int filepos=0; int filesize=0; char s[250]; int recvsize=0; int main(viod) { fp=fopen("server","rb"); fseek(fp,0,SEEK_END); filesize=ftell(fp); rewind(fp); while(recvsize != filesize) { fseek(fp,filepos,SEEK_SET); int readsize=fread(s,sizeof(char),250,fp); filepos=ftell(fp); recvsize+=readsize; if((stream=fopen("TEST.c","wb"))==NULL) { fprintf(stderr,"cannot open output file.\n"); return 1; } fwrite(&s,sizeof(char),250,stream); fclose(stream); fclose(fp); } return 0; }
出错:
*** glibc detected *** ./write: double free or corruption (top): 0x081c0008 ***
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(+0x6ebc2)[0x68cbc2]
/lib/i386-linux-gnu/libc.so.6(+0x6f862)[0x68d862]
/lib/i386-linux-gnu/libc.so.6(cfree+0x6d)[0x69094d]
/lib/i386-linux-gnu/libc.so.6(fclose+0x154)[0x67c0b4]
./write[0x8048706]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0x637113]
./write[0x8048501]
======= Memory map: ========
0061e000-00794000 r-xp 00000000 08:01 394150 /lib/i386-linux-gnu/libc-2.13.so
00794000-00796000 r--p 00176000 08:01 394150 /lib/i386-linux-gnu/libc-2.13.so
00796000-00797000 rw-p 00178000 08:01 394150 /lib/i386-linux-gnu/libc-2.13.so
00797000-0079a000 rw-p 00000000 00:00 0
007ee000-007ef000 r-xp 00000000 00:00 0 [vdso]
00ad7000-00af3000 r-xp 00000000 08:01 394171 /lib/i386-linux-gnu/libgcc_s.so.1
00af3000-00af4000 r--p 0001b000 08:01 394171 /lib/i386-linux-gnu/libgcc_s.so.1
00af4000-00af5000 rw-p 0001c000 08:01 394171 /lib/i386-linux-gnu/libgcc_s.so.1
00fca000-00fe8000 r-xp 00000000 08:01 394137 /lib/i386-linux-gnu/ld-2.13.so
00fe8000-00fe9000 r--p 0001d000 08:01 394137 /lib/i386-linux-gnu/ld-2.13.so
00fe9000-00fea000 rw-p 0001e000 08:01 394137 /lib/i386-linux-gnu/ld-2.13.so
08048000-08049000 r-xp 00000000 08:01 416755 /home/zhayun/write
08049000-0804a000 r--p 00000000 08:01 416755 /home/zhayun/write
0804a000-0804b000 rw-p 00001000 08:01 416755 /home/zhayun/write
081c0000-081e1000 rw-p 00000000 00:00 0 [heap]
b7600000-b7621000 rw-p 00000000 00:00 0
b7621000-b7700000 ---p 00000000 00:00 0
b778c000-b778d000 rw-p 00000000 00:00 0
b779a000-b779e000 rw-p 00000000 00:00 0
bf8be000-bf8df000 rw-p 00000000 00:00 0 [stack]
已放弃
gdb 调试提示:Program received signal SIGABRT, Aborted.
作者: yuncha299792458 发布时间: 2011-11-26
while中,去掉:fclose(fp);
关闭文件后,在试图读取,必然会core啊。。。
关闭文件后,在试图读取,必然会core啊。。。
作者: zheng_ai 发布时间: 2011-11-27
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28