Skip to content

Commit

Permalink
Allocate s% other_star_info after do_mesh_plan call to avoid segfault…
Browse files Browse the repository at this point in the history
… from double freeing if do_mesh_plan fails (#630)
  • Loading branch information
warrickball committed Apr 5, 2024
1 parent 5992b8e commit 5619904
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
3 changes: 2 additions & 1 deletion docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ New Features
Bug Fixes
---------


MESA no longer produces a segmentation fault if it tries to increase
the number of cells beyond ``max_allowed_nz``.


Changes in r24.03.1
Expand Down
26 changes: 13 additions & 13 deletions star/private/adjust_mesh.f90
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,6 @@ integer function remesh(s)

s% mesh_call_number = s% mesh_call_number + 1

if (.not. associated(s% other_star_info)) then
allocate(s% other_star_info)
prv => s% other_star_info
c => null()
else
prv => s% other_star_info
c => copy_info
c = prv
end if

prv = s ! this makes copies of pointers and scalars

sum_L_other = 0
sum_L_other_limit = Lsun
do j=1,num_categories
Expand Down Expand Up @@ -319,11 +307,23 @@ integer function remesh(s)
call dealloc
return
end if

nz = nz_new
s% nz = nz
nvar = s% nvar_total

if (.not. associated(s% other_star_info)) then
allocate(s% other_star_info)
prv => s% other_star_info
c => null()
else
prv => s% other_star_info
c => copy_info
c = prv
end if

prv = s ! this makes copies of pointers and scalars

if (dbg_remesh .or. dbg) write(*,*) 'call resize_star_info_arrays'
call resize_star_info_arrays(s, c, ierr)
if (ierr /= 0) then
Expand Down

0 comments on commit 5619904

Please sign in to comment.