diff options
author | George Burgess IV <gbiv@google.com> | 2018-04-24 16:38:13 -0700 |
---|---|---|
committer | George Burgess IV <gbiv@google.com> | 2018-04-24 16:58:54 -0700 |
commit | 156465e14e5f3caac3255f00fe74a7ef520fd17a (patch) | |
tree | a00ac34a3d66bfbf9cf9cd9314d4f03e9026714f /bcinfo | |
parent | 243707c31ece17e93c81218b98fb7b0fb2e238d2 (diff) | |
download | libbcc-156465e14e5f3caac3255f00fe74a7ef520fd17a.tar.gz |
Fix a memory leak
This fixes multiple memory leaks. They all boil down to "this function
was called multiple times, in which case we'd leak old member values",
or "we exited early from the function, and forgot to let go of these
`Tmp` variables."
Note that this CL assumes that we don't try to hold on to e.g. the slot
list across a call to populateObjectSlotMetadata.
Bug: None
Test: mma. No more memory leak complaints.
Change-Id: I6b44b7f4ef858d4ae99b413df8d84f00fb4766df
Diffstat (limited to 'bcinfo')
-rw-r--r-- | bcinfo/MetadataExtractor.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/bcinfo/MetadataExtractor.cpp b/bcinfo/MetadataExtractor.cpp index 78d94e5..439d121 100644 --- a/bcinfo/MetadataExtractor.cpp +++ b/bcinfo/MetadataExtractor.cpp @@ -290,9 +290,7 @@ bool MetadataExtractor::populateObjectSlotMetadata( return true; } - uint32_t *TmpSlotList = new uint32_t[mObjectSlotCount]; - memset(TmpSlotList, 0, mObjectSlotCount * sizeof(*TmpSlotList)); - + std::unique_ptr<uint32_t[]> TmpSlotList(new uint32_t[mObjectSlotCount]()); for (size_t i = 0; i < mObjectSlotCount; i++) { llvm::MDNode *ObjectSlot = ObjectSlotMetadata->getOperand(i); if (ObjectSlot != nullptr && ObjectSlot->getNumOperands() == 1) { @@ -306,8 +304,8 @@ bool MetadataExtractor::populateObjectSlotMetadata( } } - mObjectSlotList = TmpSlotList; - + delete [] mObjectSlotList; + mObjectSlotList = TmpSlotList.release(); return true; } @@ -441,9 +439,9 @@ bool MetadataExtractor::populateForEachMetadata( return true; } - uint32_t *TmpSigList = new uint32_t[mExportForEachSignatureCount]; - const char **TmpNameList = new const char*[mExportForEachSignatureCount]; - uint32_t *TmpInputCountList = new uint32_t[mExportForEachSignatureCount]; + std::unique_ptr<uint32_t[]> TmpSigList(new uint32_t[mExportForEachSignatureCount]); + std::unique_ptr<const char *[]> TmpNameList(new const char*[mExportForEachSignatureCount]); + std::unique_ptr<uint32_t[]> TmpInputCountList(new uint32_t[mExportForEachSignatureCount]); for (size_t i = 0; i < mExportForEachSignatureCount; i++) { llvm::MDNode *SigNode = Signatures->getOperand(i); @@ -489,9 +487,14 @@ bool MetadataExtractor::populateForEachMetadata( TmpNameList[0] = RootName; } - mExportForEachNameList = TmpNameList; - mExportForEachSignatureList = TmpSigList; - mExportForEachInputCountList = TmpInputCountList; + delete [] mExportForEachNameList; + mExportForEachNameList = TmpNameList.release(); + + delete [] mExportForEachSignatureList; + mExportForEachSignatureList = TmpSigList.release(); + + delete [] mExportForEachInputCountList; + mExportForEachInputCountList = TmpInputCountList.release(); return true; } |