Color Scheme
搜索用户
帐号
密码
注册
old site http://222.195.74.11/
English Version 当前位置: 首页 >> 苏彦青 : 个人简历 - 博客

Ubuntu

Poster:

1. 转载fortran: Double free or corruption error 应用-fbounds-check
转自:http://hi.baidu.com/qi_hao/blog/item/555e0bed86e229deb21cb1e3.html

Link: http://jblevins.org/computing/fortran/double-free
A double free or corruption error in a Fortran program means that
your program has somehow invoked the free() C runtime function
with an invalid pointer. This can happen if it is using dynamic
memory allocation or if it is calling free() in C directly somehow.

A common cause of this error is that your code has overwritten
memory somewhere due to an out-of-bounds array index.
Take the following program, for example:

!! Generates a "double free or corruption" error.
program free
integer, dimension(:), allocatable :: data
integer :: i

allocate(data(5))
do i = 1, 5
data(i-1) = i
end do
deallocate(data)
end program free

After compiling and running we have the following error:

% gfortran -o free free.f90
% ./free
*** glibc detected *** ./free: double free or corruption (out): 0x0000000000607590 ***
======= Backtrace: =========
/lib/libc.so.6[0x2b8d50ef0968]
/lib/libc.so.6(cfree+0x76)[0x2b8d50ef2a76]
./free[0x400859]
./free[0x4008ac]
/lib/libc.so.6(__libc_start_main+0xe6)[0x2b8d50e9b1a6]
./free[0x4006a9]
[...]
Aborted

To check invalid array indexing using the GNU Fortran compiler,
compile the program with the -fbounds-check flag and run it
again (see gfortran(1) for details). If any array indices are
out-of-bounds, you will see an error message like the following:

% gfortran -fbounds-check -o free free.f90
% ./free
At line 8 of file free.f90
Fortran runtime error: Array reference out of bounds for array 'data', lower bound of dimension 1 exceeded (0 < 1)

This points us directly to line 8 of free.f90 where we see that
the first iteration of the loop writes to the invalid element
data(-1). Changing the i-1 to i fixes the problem.
苏彦青
Posted at 2011-05-06 11:16 CST
Last modified at 2011-05-06 11:16 CST
Link to this poster
Top


位置 | 访问统计 | FAQ
Best view under the 1024x768 resolution and with the normal size of fonts.
Designed & developed by Yuming Wang, run for 6364 days since December 15, 2006, and last upgraded on May 28th, 2009.
Powered by Apache + PHP coded cOpfOs 3.11.1 last upgraded on February 22nd, 2010.
Copyright © 2006, all rights reserved.