<div dir="ltr"><div dir="ltr">On Sun, Mar 3, 2019 at 1:03 PM Yuyun Yang via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div lang="EN-US">
<div class="gmail-m_7687454233436876500WordSection1">
<p class="MsoNormal">I tried compiling without the sanitizer and running on valgrind. Got a bunch of errors “Uninitialised value was created by a stack allocation at 0x41B280: ComputeVel_qd::computeVel(double*, double, int&, int)”.</p></div></div></blockquote><div><br></div><div>There is no memory management code here, so other parts of the code must be relevant.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div class="gmail-m_7687454233436876500WordSection1"><p class="MsoNormal"> </p><p class="MsoNormal"><u></u></p>
<p class="MsoNormal">HEAP SUMMARY:<u></u><u></u></p>
<p class="MsoNormal">==74== in use at exit: 96,637 bytes in 91 blocks<u></u><u></u></p>
<p class="MsoNormal">==74== total heap usage: 47,774 allocs, 47,522 frees, 308,253,653 bytes allocated<u></u><u></u></p>
<p class="MsoNormal">LEAK SUMMARY:<u></u><u></u></p>
<p class="MsoNormal">==74== definitely lost: 0 bytes in 0 blocks<u></u><u></u></p>
<p class="MsoNormal">==74== indirectly lost: 0 bytes in 0 blocks<u></u><u></u></p>
<p class="MsoNormal">==74== possibly lost: 0 bytes in 0 blocks<u></u><u></u></p>
<p class="MsoNormal">==74== still reachable: 96,637 bytes in 91 blocks<u></u><u></u></p>
<p class="MsoNormal">==74== suppressed: 0 bytes in 0 blocks<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">The error is located in the attached code (I’ve extracted only the relevant functions), but I couldn’t figure out what is wrong. Is this causing the memory corruption/double free error that happens when I execute the code?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks a lot for your help.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Best regards,<u></u><u></u></p>
<p class="MsoNormal">Yuyun<u></u><u></u></p>
<p class="MsoNormal"><u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0in 0in">
<p class="MsoNormal"><b>From:</b> Zhang, Junchao <<a href="mailto:jczhang@mcs.anl.gov" target="_blank">jczhang@mcs.anl.gov</a>> <br>
<b>Sent:</b> Friday, March 1, 2019 7:36 AM<br>
<b>To:</b> Yuyun Yang <<a href="mailto:yyang85@stanford.edu" target="_blank">yyang85@stanford.edu</a>><br>
<b>Subject:</b> Re: [petsc-users] AddressSanitizer: attempting free on address which was not malloc()-ed<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">On Fri, Mar 1, 2019 at 1:02 AM Yuyun Yang <<a href="mailto:yyang85@stanford.edu" target="_blank">yyang85@stanford.edu</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div id="gmail-m_7687454233436876500gmail-m_-2605494106314756674compose-container">
<div>
<div>
<p class="MsoNormal">Actually, I also saw a line at the beginning of valgrind saying "shadow memory range interleaves with an existing memory mapping. ASan cannot proceed properly. ABORTING." I guess the code didn't really run through valgrind since it aborted.
Should I remove the address sanitizer flag when compiling?<u></u><u></u></p>
</div>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal">From the message, it seems ASan (not valgrind) aborted. You can try to compile without sanitizer and then run with valgrind. If no problem, then it is probably a sanitizer issue.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div id="gmail-m_7687454233436876500gmail-m_-2605494106314756674compose-container">
<div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Get <a href="https://aka.ms/o0ukef" target="_blank">Outlook for iOS</a><u></u><u></u></p>
</div>
</div>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="3" width="98%" align="center">
</div>
<div id="gmail-m_7687454233436876500gmail-m_-2605494106314756674divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> Yuyun Yang<br>
<b>Sent:</b> Thursday, February 28, 2019 10:54:57 PM<br>
<b>To:</b> Zhang, Junchao<br>
<b>Subject:</b> Re: [petsc-users] AddressSanitizer: attempting free on address which was not malloc()-ed</span>
<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<div>
<div id="gmail-m_7687454233436876500gmail-m_-2605494106314756674compose-container">
<div>
<div>
<p class="MsoNormal">Hmm, still getting the same error from address sanitizer even though valgrind shows no errors and no leaks are possible.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Should I ignore that error? My results did run alright.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Best,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Yuyun<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Get <a href="https://aka.ms/o0ukef" target="_blank">Outlook for iOS</a><u></u><u></u></p>
</div>
</div>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="3" width="98%" align="center">
</div>
<div id="gmail-m_7687454233436876500gmail-m_-2605494106314756674divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> Zhang, Junchao <<a href="mailto:jczhang@mcs.anl.gov" target="_blank">jczhang@mcs.anl.gov</a>><br>
<b>Sent:</b> Wednesday, February 27, 2019 8:27:17 PM<br>
<b>To:</b> Yuyun Yang<br>
<b>Cc:</b> Matthew Knepley; <a href="mailto:petsc-users@mcs.anl.gov" target="_blank">
petsc-users@mcs.anl.gov</a><br>
<b>Subject:</b> Re: [petsc-users] AddressSanitizer: attempting free on address which was not malloc()-ed</span>
<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">Try the following to see if you can catch the bug easily: 1) Get error code for each petsc function and check it with CHKERRQ; 2) Link your code with a petsc library with debugging enabled (configured with --with-debugging=1); 3) Run your
code with valgrind<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal">--Junchao Zhang<u></u><u></u></p>
</div>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Wed, Feb 27, 2019 at 9:04 PM Yuyun Yang <<a href="mailto:yyang85@stanford.edu" target="_blank">yyang85@stanford.edu</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div id="gmail-m_7687454233436876500gmail-m_-2605494106314756674gmail-m_1447584671225542270compose-container">
<div>
<div>
<p class="MsoNormal">Hi Junchao,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">This code actually involves a lot of classes and is pretty big. Might be an overkill for me to send everything to you. I'd like to know if I see this sort of error message, which points to this domain file, is it possible that the problem
happens in another file (whose operations are linked to this one)? If so, I'll debug a little more and maybe send you more useful information later.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Best regards,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Yuyun<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Get <a href="https://aka.ms/o0ukef" target="_blank">Outlook for iOS</a><u></u><u></u></p>
</div>
</div>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="3" width="98%" align="center">
</div>
<div id="gmail-m_7687454233436876500gmail-m_-2605494106314756674gmail-m_1447584671225542270divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> Zhang, Junchao <<a href="mailto:jczhang@mcs.anl.gov" target="_blank">jczhang@mcs.anl.gov</a>><br>
<b>Sent:</b> Wednesday, February 27, 2019 6:24:13 PM<br>
<b>To:</b> Yuyun Yang<br>
<b>Cc:</b> Matthew Knepley; <a href="mailto:petsc-users@mcs.anl.gov" target="_blank">
petsc-users@mcs.anl.gov</a><br>
<b>Subject:</b> Re: [petsc-users] AddressSanitizer: attempting free on address which was not malloc()-ed</span>
<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Could you provide a compilable and runnable test so I can try it?<br clear="all">
<u></u><u></u></p>
<div>
<div>
<div>
<p class="MsoNormal">--Junchao Zhang<u></u><u></u></p>
</div>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Wed, Feb 27, 2019 at 7:34 PM Yuyun Yang <<a href="mailto:yyang85@stanford.edu" target="_blank">yyang85@stanford.edu</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">Thanks, I fixed that, but I’m not actually calling the testScatters() function in my implementation (in the constructor, the only functions I called are setFields and setScatters).
So the problem couldn’t have been that?<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Best,<u></u><u></u></p>
<p class="MsoNormal">Yuyun<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0in 0in">
<p class="MsoNormal"><b>From:</b> Zhang, Junchao <<a href="mailto:jczhang@mcs.anl.gov" target="_blank">jczhang@mcs.anl.gov</a>>
<br>
<b>Sent:</b> Wednesday, February 27, 2019 10:50 AM<br>
<b>To:</b> Yuyun Yang <<a href="mailto:yyang85@stanford.edu" target="_blank">yyang85@stanford.edu</a>><br>
<b>Cc:</b> Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>>;
<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a><br>
<b>Subject:</b> Re: [petsc-users] AddressSanitizer: attempting free on address which was not malloc()-ed<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">On Wed, Feb 27, 2019 at 10:41 AM Yuyun Yang via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<div>
<div>
<p class="MsoNormal">I called VecDestroy() in the destructor for this object – is that not the right way to do it?<u></u><u></u></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal">In Domain::testScatters(), you have many VecDuplicate(,&out), You need to VecDestroy(&out) before doing new VecDuplicate(,&out); <u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<div>
<div>
<p class="MsoNormal">How do I implement CHECK ALL RETURN CODES?<u></u><u></u></p>
</div>
</div>
</blockquote>
<p class="MsoNormal">For each PETSc function, do ierr = ...; CHKERRQ(ierr);
<u></u><u></u></p>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"><b>From:</b> Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>>
<br>
<b>Sent:</b> Wednesday, February 27, 2019 7:24 AM<br>
<b>To:</b> Yuyun Yang <<a href="mailto:yyang85@stanford.edu" target="_blank">yyang85@stanford.edu</a>><br>
<b>Cc:</b> <a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a><br>
<b>Subject:</b> Re: [petsc-users] AddressSanitizer: attempting free on address which was not malloc()-ed<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">You call VecDuplicate() a bunch, but VecDestroy() only once in the bottom function. This is wrong.<u></u><u></u></p>
<div>
<p class="MsoNormal">Also, CHECK ALL RETURN CODES. This is the fastest way to find errors.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Matt<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">On Wed, Feb 27, 2019 at 2:06 AM Yuyun Yang via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<div>
<div>
<p class="MsoNormal">Hello team,<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">I ran into the address sanitizer error that I hope you could help me with. I don’t really know what’s wrong with the way the code frees memory. The relevant code file is attached.
The line number following domain.cpp specifically referenced to the vector _q, which seems a little odd, since some other vectors are constructed and freed the same way.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">==1719==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x61f0000076c0 in thread T0<u></u><u></u></p>
<p class="MsoNormal"> #0 0x7fbf195282ca in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x982ca)<u></u><u></u></p>
<p class="MsoNormal"> #1 0x7fbf1706f895 in PetscFreeAlign /home/yyy910805/petsc/src/sys/memory/mal.c:87<u></u><u></u></p>
<p class="MsoNormal"> #2 0x7fbf1731a898 in VecDestroy_Seq /home/yyy910805/petsc/src/vec/vec/impls/seq/bvec2.c:788<u></u><u></u></p>
<p class="MsoNormal"> #3 0x7fbf1735f795 in VecDestroy /home/yyy910805/petsc/src/vec/vec/interface/vector.c:408<u></u><u></u></p>
<p class="MsoNormal"> #4 0x40dd0a in Domain::~Domain() /home/yyy910805/scycle/source/domain.cpp:132<u></u><u></u></p>
<p class="MsoNormal"> #5 0x40b479 in main /home/yyy910805/scycle/source/main.cpp:242<u></u><u></u></p>
<p class="MsoNormal"> #6 0x7fbf14d2082f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)<u></u><u></u></p>
<p class="MsoNormal"> #7 0x4075d8 in _start (/home/yyy910805/scycle/source/main+0x4075d8)<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">0x61f0000076c0 is located 1600 bytes inside of 3220-byte region [0x61f000007080,0x61f000007d14)<u></u><u></u></p>
<p class="MsoNormal">allocated by thread T0 here:<u></u><u></u></p>
<p class="MsoNormal"> #0 0x7fbf19528b32 in __interceptor_memalign (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98b32)<u></u><u></u></p>
<p class="MsoNormal"> #1 0x7fbf1706f7e0 in PetscMallocAlign /home/yyy910805/petsc/src/sys/memory/mal.c:41<u></u><u></u></p>
<p class="MsoNormal"> #2 0x7fbf17073022 in PetscTrMallocDefault /home/yyy910805/petsc/src/sys/memory/mtr.c:183<u></u><u></u></p>
<p class="MsoNormal"> #3 0x7fbf170710a1 in PetscMallocA /home/yyy910805/petsc/src/sys/memory/mal.c:397<u></u><u></u></p>
<p class="MsoNormal"> #4 0x7fbf17326fb0 in VecCreate_Seq /home/yyy910805/petsc/src/vec/vec/impls/seq/bvec3.c:35<u></u><u></u></p>
<p class="MsoNormal"> #5 0x7fbf1736f560 in VecSetType /home/yyy910805/petsc/src/vec/vec/interface/vecreg.c:51<u></u><u></u></p>
<p class="MsoNormal"> #6 0x7fbf1731afae in VecDuplicate_Seq /home/yyy910805/petsc/src/vec/vec/impls/seq/bvec2.c:807<u></u><u></u></p>
<p class="MsoNormal"> #7 0x7fbf1735eff7 in VecDuplicate /home/yyy910805/petsc/src/vec/vec/interface/vector.c:379<u></u><u></u></p>
<p class="MsoNormal"> #8 0x4130de in Domain::setFields() /home/yyy910805/scycle/source/domain.cpp:431<u></u><u></u></p>
<p class="MsoNormal"> #9 0x40c60a in Domain::Domain(char const*) /home/yyy910805/scycle/source/domain.cpp:57<u></u><u></u></p>
<p class="MsoNormal"> #10 0x40b433 in main /home/yyy910805/scycle/source/main.cpp:242<u></u><u></u></p>
<p class="MsoNormal"> #11 0x7fbf14d2082f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">SUMMARY: AddressSanitizer: bad-free ??:0 __interceptor_free<u></u><u></u></p>
<p class="MsoNormal">==1719==ABORTING<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Thanks very much!<u></u><u></u></p>
<p class="MsoNormal">Yuyun<u></u><u></u></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br clear="all">
<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<p class="MsoNormal">--
<u></u><u></u></p>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>