[PATCH] D136826: [clang][Interp] Make sure we free() allocated InitMaps

Shafik Yaghmour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 28 18:22:00 PDT 2022


shafik added inline comments.


================
Comment at: clang/lib/AST/Interp/Descriptor.cpp:46
+
+  Ptr += sizeof(InitMap *);
   for (unsigned I = 0, NE = D->getNumElems(); I < NE; ++I) {
----------------
aaron.ballman wrote:
> shafik wrote:
> > I believe `Ptr` is not longer valid b/c of `free(IM)` b/c what `Ptr` points to has not been free'ed 
> > 
> > I am looking at the wording now but I am curious what @aaron.ballman thinks.
> How I see it is that it's converting `Ptr` to an `IntMap **`, dereferencing that back to `IntMap *` and then freeing *that* pointer. So it doesn't free `Ptr` itself, but what `Ptr` points to.
Right but the address is no longer valid even if the type we free'ed as is different. So the pointer is not longer pointing to a valid location. At least that is how I have seen it explained in other contexts but I have to dig up a reference.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136826/new/

https://reviews.llvm.org/D136826



More information about the cfe-commits mailing list