LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-27-2015, 11:50 AM   #1
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Rep: Reputation: Disabled
DEALLOCATE statement in Gfortran kills a program. Why?


I have this main in Gfortran. It works perfectly with one problem. If I include DEALLOCATE the program craches. In this particular configuration this problem is not lethal. By the time of the crash all execution is done and I usually simply comment this statement out, however, in real life it will be a serious problem. The main will eventually be converted into a subroutine with a loop and the memory will be allocated and deallocated many times. What is the problem? This is the code:

Code:
program main
   use fft_vect_mod    ! must also be in every procedure without exceptions.
   implicit none   
   DOUBLE COMPLEX, DIMENSION (:), POINTER :: Input 
   DOUBLE COMPLEX, DIMENSION (:), POINTER :: Output  
   DOUBLE COMPLEX :: yy
   integer :: N = 1024, jj = 1, sv
   REAL*8 :: xx, blackmanHarrisWindow  
   ALLOCATE (Input(N),Output(N))
   open (unit=1,file="cppFFTinp.dat",status="old")
   open (unit=2,file="cppFFTout.dat",status="old")
   open (unit=3,file="cppFFTcoef.dat",status="old")
   do while (jj < N)
     xx = blackmanHarrisWindow (jj,N)
     yy = CMPLX (xx,0.0D0)     
     Input(jj) = yy
     write (1,*) DBLE (Input(jj))      
     jj = jj + 1
   enddo   
   call Forward (Input, Output, N)
   jj = 1
   do while (jj < N)
     write (3,*) DBLE (Output(jj))
     jj = jj + 1
   enddo
   call Inverse (Output, Input, N, .true.)
   jj = 1
   do while (jj < N)
     write (2,*) DBLE (Input(jj))
     jj = jj + 1
   enddo
   close (unit=1)
   close (unit=2)
   close (unit=3)
   DEALLOCATE (Input,Output,STAT=sv)
 end program main
and this is the core dump:

Code:
./a.out
*** glibc detected *** ./a.out: double free or corruption (!prev): 0x0940fc18 ***
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(+0x75ee2)[0xb74f2ee2]
./a.out[0x8049045]
./a.out[0x80490d6]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0xb74964d3]
./a.out[0x8048741]
======= Memory map: ========
08048000-0804a000 r-xp 00000000 08:01 10747909   /home/alex/GFORTRAN-APPS/FFT/LIBROW-FFT/a.out
0804a000-0804b000 r--p 00001000 08:01 10747909   /home/alex/GFORTRAN-APPS/FFT/LIBROW-FFT/a.out
0804b000-0804c000 rw-p 00002000 08:01 10747909   /home/alex/GFORTRAN-APPS/FFT/LIBROW-FFT/a.out
0940e000-0942f000 rw-p 00000000 00:00 0          [heap]
b73d7000-b73f3000 r-xp 00000000 08:01 525207     /lib/i386-linux-gnu/libgcc_s.so.1
b73f3000-b73f4000 r--p 0001b000 08:01 525207     /lib/i386-linux-gnu/libgcc_s.so.1
b73f4000-b73f5000 rw-p 0001c000 08:01 525207     /lib/i386-linux-gnu/libgcc_s.so.1
b7408000-b7409000 rw-p 00000000 00:00 0 
b7409000-b747b000 r-xp 00000000 08:01 6820765    /usr/lib/i386-linux-gnu/libquadmath.so.0.0.0
b747b000-b747c000 r--p 00071000 08:01 6820765    /usr/lib/i386-linux-gnu/libquadmath.so.0.0.0
b747c000-b747d000 rw-p 00072000 08:01 6820765    /usr/lib/i386-linux-gnu/libquadmath.so.0.0.0
b747d000-b7620000 r-xp 00000000 08:01 525186     /lib/i386-linux-gnu/libc-2.15.so
b7620000-b7622000 r--p 001a3000 08:01 525186     /lib/i386-linux-gnu/libc-2.15.so
b7622000-b7623000 rw-p 001a5000 08:01 525186     /lib/i386-linux-gnu/libc-2.15.so
b7623000-b7627000 rw-p 00000000 00:00 0 
b7627000-b7651000 r-xp 00000000 08:01 525218     /lib/i386-linux-gnu/libm-2.15.so
b7651000-b7652000 r--p 00029000 08:01 525218     /lib/i386-linux-gnu/libm-2.15.so
b7652000-b7653000 rw-p 0002a000 08:01 525218     /lib/i386-linux-gnu/libm-2.15.so
b7653000-b7751000 r-xp 00000000 08:01 6815786    /usr/lib/i386-linux-gnu/libgfortran.so.3.0.0
b7751000-b7752000 r--p 000fe000 08:01 6815786    /usr/lib/i386-linux-gnu/libgfortran.so.3.0.0
b7752000-b7753000 rw-p 000ff000 08:01 6815786    /usr/lib/i386-linux-gnu/libgfortran.so.3.0.0
b7753000-b7754000 rw-p 00000000 00:00 0 
b7766000-b7769000 rw-p 00000000 00:00 0 
b7769000-b776a000 r-xp 00000000 00:00 0          [vdso]
b776a000-b778a000 r-xp 00000000 08:01 525166     /lib/i386-linux-gnu/ld-2.15.so
b778a000-b778b000 r--p 0001f000 08:01 525166     /lib/i386-linux-gnu/ld-2.15.so
b778b000-b778c000 rw-p 00020000 08:01 525166     /lib/i386-linux-gnu/ld-2.15.so
bfca3000-bfcc4000 rw-p 00000000 00:00 0          [stack]
Aborted (core dumped)

Last edited by AlexBB; 03-27-2015 at 04:37 PM.
 
Old 03-27-2015, 03:03 PM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Have you tried making them ALLOCATABLE instead of POINTER?

Code:
   DOUBLE COMPLEX, DIMENSION (:), ALLOCATABLE :: Input 
   DOUBLE COMPLEX, DIMENSION (:), ALLOCATABLE :: Output
 
Old 03-27-2015, 03:32 PM   #3
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Original Poster
Rep: Reputation: Disabled
Yes, I've tried. Something went wrong and it either did not compile or somehow it did not work, I now don't remember. Could be that it compiled but crashed on execution. The thing is this POINTER variant does work in everything except DEALLOCATE and it is very comforting.

Last edited by AlexBB; 03-27-2015 at 04:36 PM.
 
Old 03-29-2015, 03:30 PM   #4
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Original Poster
Rep: Reputation: Disabled
estabroo, I just tried ALLOCATABLE without pointers and it worked with DEALLOCATE perfectly well.

Thanks, - Alex
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Gfortran statement does not compile AlexBB Linux - Newbie 38 12-05-2016 07:19 PM
[SOLVED] READ statement in GFortran does not work. AlexBB Programming 2 11-05-2014 07:18 PM
gfortran: Syntax error in DATA statement at (1) science_guy Programming 1 10-16-2009 12:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration