Fix leak in aidl_unittests
Turning on "sanitizer: address" revealed the leak in the test code.
Bug: n/a
Test: aidl_unittests
Change-Id: Id13820cff676d998934d6b1485d453f37397d696
diff --git a/aidl_language.cpp b/aidl_language.cpp
index 0cbef0b..5941f35 100644
--- a/aidl_language.cpp
+++ b/aidl_language.cpp
@@ -167,9 +167,9 @@
__builtin_unreachable();
}
-AidlAnnotation* AidlAnnotation::Parse(
+std::unique_ptr<AidlAnnotation> AidlAnnotation::Parse(
const AidlLocation& location, const string& name,
- std::map<std::string, std::shared_ptr<AidlConstantValue>>* parameter_list,
+ std::map<std::string, std::shared_ptr<AidlConstantValue>> parameter_list,
const Comments& comments) {
const Schema* schema = nullptr;
for (const Schema& a_schema : AllSchemas()) {
@@ -187,19 +187,16 @@
}
stream << ".";
AIDL_ERROR(location) << stream.str();
- return nullptr;
- }
- if (parameter_list == nullptr) {
- return new AidlAnnotation(location, *schema, {}, comments);
+ return {};
}
- return new AidlAnnotation(location, *schema, std::move(*parameter_list), comments);
+ return std::unique_ptr<AidlAnnotation>(
+ new AidlAnnotation(location, *schema, std::move(parameter_list), comments));
}
-AidlAnnotation::AidlAnnotation(
- const AidlLocation& location, const Schema& schema,
- std::map<std::string, std::shared_ptr<AidlConstantValue>>&& parameters,
- const Comments& comments)
+AidlAnnotation::AidlAnnotation(const AidlLocation& location, const Schema& schema,
+ std::map<std::string, std::shared_ptr<AidlConstantValue>> parameters,
+ const Comments& comments)
: AidlNode(location, comments), schema_(schema), parameters_(std::move(parameters)) {}
struct ConstReferenceFinder : AidlVisitor {