Page MenuHomePhabricator

Fix a leak in `ASTUnit::LoadFromCommandLine()` wehn compiler invocation fails

Authored by bstaletic on Nov 2 2020, 5:36 AM.


  1. Here we allocate buffers to hold the contents of unsaved files.
  2. The RemappedFiles vector is then passed to ASTUnit::LoadFromCommandLine() as an ArrayRef, here
  3. In ASTUnit::LoadFromCommandLine() we try to make a compiler invocation and exit early if that fails.
  4. If we did exit early from that function, both Unit and UnitErr are nullptr, making the function exit without ever cleaning up the memory allocations from step 1.


  1. The function allocating all those RemappedFile objects is not actually the same as the one deallocating, in the happy case.

1.1. I did not figure out where exactly does it get deleted, because the above seems to be enough data for now.

  1. My attempted solution is to iterate over remapped files and deallocate in this block, but it seems odd to deallocate through ArrayRef.


Diff Detail

Event Timeline

bstaletic created this revision.Nov 2 2020, 5:36 AM
bstaletic requested review of this revision.Nov 2 2020, 5:36 AM
bstaletic updated this revision to Diff 303624.Nov 7 2020, 1:10 AM

Fixed the code formatting error.

aprantl accepted this revision.Dec 4 2020, 6:04 PM
This revision is now accepted and ready to land.Dec 4 2020, 6:04 PM