Stop leaks.
Bug: 37749857
Test: the following to see leaks
export ASAN_OPTIONS=""
mma SANITIZE_HOST=address
Test: runtests_asan.sh
Change-Id: I15b5da5a35262f13835f41f1ae8e1ffb853bceda
diff --git a/Android.bp b/Android.bp
index 44ef1b2..882563e 100644
--- a/Android.bp
+++ b/Android.bp
@@ -30,6 +30,12 @@
windows: {
enabled: true,
},
+ host: {
+ cflags: [
+ "-O0",
+ "-g",
+ ],
+ },
},
}
diff --git a/aidl_language_y.yy b/aidl_language_y.yy
index bba7f0a..d131578 100644
--- a/aidl_language_y.yy
+++ b/aidl_language_y.yy
@@ -72,12 +72,17 @@
std::vector<std::unique_ptr<AidlTypeSpecifier>>* type_args;
}
+%destructor { } <character>
+%destructor { } <direction>
+%destructor { delete ($$); } <*>
+
%token<token> ANNOTATION "annotation"
%token<token> C_STR "string literal"
%token<token> IDENTIFIER "identifier"
%token<token> INTERFACE "interface"
%token<token> PARCELABLE "parcelable"
%token<token> ONEWAY "oneway"
+%token<token> ENUM "enum"
%token<character> CHARVALUE "char literal"
%token<token> FLOATVALUE "float literal"
@@ -95,7 +100,6 @@
%token PACKAGE "package"
%token TRUE_LITERAL "true"
%token FALSE_LITERAL "false"
-%token ENUM "enum"
%type<declaration> decl
%type<variable_list> variable_decls
@@ -204,17 +208,24 @@
parcelable_decl
: PARCELABLE qualified_name ';' {
$$ = new AidlParcelable(loc(@2), $2, ps->Package(), $1->GetComments());
+ delete $1;
}
| PARCELABLE qualified_name CPP_HEADER C_STR ';' {
$$ = new AidlParcelable(loc(@2), $2, ps->Package(), $1->GetComments(), $4->GetText());
+ delete $1;
+ delete $4;
}
| PARCELABLE identifier '{' variable_decls '}' {
AidlQualifiedName* name = new AidlQualifiedName(loc(@2), $2->GetText(), $2->GetComments());
$$ = new AidlStructuredParcelable(loc(@2), name, ps->Package(), $1->GetComments(), $4);
+ delete $1;
+ delete $2;
+ delete $4;
}
| PARCELABLE error ';' {
ps->AddError();
- $$ = NULL;
+ $$ = nullptr;
+ delete $1;
};
variable_decls
@@ -231,10 +242,12 @@
variable_decl
: type identifier ';' {
$$ = new AidlVariableDeclaration(loc(@2), $1, $2->GetText());
+ delete $2;
}
| type identifier '=' constant_value ';' {
// TODO(b/123321528): Support enum type default assignments (TestEnum foo = TestEnum.FOO).
$$ = new AidlVariableDeclaration(loc(@2), $1, $2->GetText(), $4);
+ delete $2;
}
| error ';' {
ps->AddError();
@@ -265,9 +278,9 @@
:
{ $$ = new std::vector<std::unique_ptr<AidlMember>>(); }
| interface_members method_decl
- { $1->push_back(std::unique_ptr<AidlMember>($2)); }
+ { $1->push_back(std::unique_ptr<AidlMember>($2)); $$ = $1; }
| interface_members constant_decl
- { $1->push_back(std::unique_ptr<AidlMember>($2)); }
+ { $1->push_back(std::unique_ptr<AidlMember>($2)); $$ = $1; }
| interface_members error ';' {
ps->AddError();
$$ = $1;
@@ -323,6 +336,7 @@
possibly_multiline_string
: C_STR {
$$ = new string($1->GetText());
+ delete $1;
}
| possibly_multiline_string '+' C_STR {
$$ = $1;
@@ -362,6 +376,7 @@
}
| enumerators ',' enumerator {
$1->push_back(std::unique_ptr<AidlEnumerator>($3));
+ $$ = $1;
}
;
@@ -374,6 +389,7 @@
enum_decl
: ENUM identifier enum_decl_body {
$$ = new AidlEnumDeclaration(loc(@2), $2->GetText(), $3, ps->Package());
+ delete $1;
delete $2;
delete $3;
}
@@ -395,6 +411,7 @@
| type identifier '(' arg_list ')' '=' INTVALUE ';' {
$$ = new AidlMethod(loc(@2), false, $1, $2->GetText(), $4, $1->GetComments(), std::stoi($7->GetText()));
delete $2;
+ delete $7;
}
| annotation_list ONEWAY type identifier '(' arg_list ')' '=' INTVALUE ';' {
const std::string& comments = ($1->size() > 0) ? $1->begin()->GetComments() : $2->GetComments();
@@ -403,6 +420,7 @@
delete $1;
delete $2;
delete $4;
+ delete $9;
};
arg_list
@@ -426,9 +444,7 @@
$$ = new AidlArgument(loc(@2), $1, $2->GetText());
delete $2;
}
- | error {
- ps->AddError();
- };
+ ;
unannotated_type
: qualified_name {
@@ -465,6 +481,7 @@
}
| type_args ',' unannotated_type {
$1->emplace_back($3);
+ $$ = $1;
};
annotation_list
@@ -476,6 +493,7 @@
$1->emplace_back(std::move(*$2));
delete $2;
}
+ $$ = $1;
};
parameter
@@ -516,6 +534,7 @@
ps->AddError();
}
$$->SetComments($1->GetComments());
+ delete $1;
};
| ANNOTATION '(' parameter_list ')' {
$$ = AidlAnnotation::Parse(loc(@1), $1->GetText(), $3);
@@ -523,6 +542,7 @@
ps->AddError();
}
$$->SetComments($1->GetComments());
+ delete $1;
delete $3;
}
diff --git a/main.cpp b/main.cpp
index d21819a..1199579 100644
--- a/main.cpp
+++ b/main.cpp
@@ -25,11 +25,6 @@
using android::aidl::Options;
-// aidl is leaky. Turn off LeakSanitizer by default. b/37749857
-extern "C" const char* __asan_default_options() {
- return "detect_leaks=0";
-}
-
int main(int argc, char* argv[]) {
android::base::InitLogging(argv);
LOG(DEBUG) << "aidl starting";
diff --git a/main_cpp.cpp b/main_cpp.cpp
index 72b3ffb..5cb778c 100644
--- a/main_cpp.cpp
+++ b/main_cpp.cpp
@@ -23,11 +23,6 @@
using android::aidl::Options;
-// aidl is leaky. Turn off LeakSanitizer by default. b/37749857
-extern "C" const char *__asan_default_options() {
- return "detect_leaks=0";
-}
-
int main(int argc, char* argv[]) {
android::base::InitLogging(argv);
LOG(DEBUG) << "aidl starting";
diff --git a/runtests_asan.sh b/runtests_asan.sh
new file mode 100755
index 0000000..b796fba
--- /dev/null
+++ b/runtests_asan.sh
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+
+# Copyright (C) 2019 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+export ASAN_OPTIONS=""
+export SANITIZE_HOST=address
+
+./runtests.sh
+