PrincetonUniversity / athena

Athena++ radiation GRMHD code and adaptive mesh refinement (AMR) framework
https://www.athena-astro.app
BSD 3-Clause "New" or "Revised" License
226 stars 122 forks source link

Is this pdata->pnext supposed to be pnew->pnext here? #528

Closed felker closed 1 year ago

felker commented 1 year ago

When reviewing #496, I ran pgen_compile with GCC 13 with all relevant warning flags turned on, and it directed me to this line: https://github.com/PrincetonUniversity/athena/blame/ca8ba578e085fe37a2962db7f5bff8d35be380a6/src/outputs/outputs.cpp#L1003

struct/dc_simple.cpp -o /Users/felker/Desktop/athena3/tst/regression/obj/dc_simple.o
src/outputs/outputs.cpp: In member function 'void OutputType::SumOutputData(MeshBlock*, int)':
src/outputs/outputs.cpp:1104:11: error: pointer 'pdata' used after 'void operator delete(void*)' [-Werror=use-after-free]
 1104 |     pdata = pdata->pnext;
      |     ~~~~~~^~~~~~~~~~~~~~
In member function 'void OutputType::ReplaceOutputDataNode(OutputData*, OutputData*)',
    inlined from 'void OutputType::SumOutputData(MeshBlock*, int)' at src/outputs/outputs.cpp:1103:26:
src/outputs/outputs.cpp:864:10: note: call to 'void operator delete(void*)' here
  864 |   delete pold;
      |          ^~~~

Even though this code dates back to 2016, I wonder if this is a bug. A nearly identical line was fixed in #32.