[vm] Fix memory leaks in --load_compilation_trace and --load_type_feedback.

Bug: https://github.com/dart-lang/sdk/issues/36208
Change-Id: I08142c1840a57fcd1023e7cd8bb26ab4039cfa9a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/96963
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
diff --git a/runtime/bin/gen_snapshot.cc b/runtime/bin/gen_snapshot.cc
index 8dfc9202..6632130 100644
--- a/runtime/bin/gen_snapshot.cc
+++ b/runtime/bin/gen_snapshot.cc
@@ -424,6 +424,7 @@
     intptr_t size = 0;
     ReadFile(load_compilation_trace_filename, &buffer, &size);
     Dart_Handle result = Dart_LoadCompilationTrace(buffer, size);
+    free(buffer);
     CHECK_RESULT(result);
   }
 
@@ -433,6 +434,7 @@
     intptr_t size = 0;
     ReadFile(load_type_feedback_filename, &buffer, &size);
     Dart_Handle result = Dart_LoadTypeFeedback(buffer, size);
+    free(buffer);
     CHECK_RESULT(result);
   }
 }
diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc
index 73351c7..f572e20 100644
--- a/runtime/bin/main.cc
+++ b/runtime/bin/main.cc
@@ -888,6 +888,7 @@
       intptr_t size = 0;
       ReadFile(Options::load_compilation_trace_filename(), &buffer, &size);
       result = Dart_LoadCompilationTrace(buffer, size);
+      free(buffer);
       CHECK_RESULT(result);
     }
     if (Options::load_type_feedback_filename() != NULL) {
@@ -895,6 +896,7 @@
       intptr_t size = 0;
       ReadFile(Options::load_type_feedback_filename(), &buffer, &size);
       result = Dart_LoadTypeFeedback(buffer, size);
+      free(buffer);
       CHECK_RESULT(result);
     }
 
diff --git a/runtime/vm/compilation_trace.cc b/runtime/vm/compilation_trace.cc
index 9009e0b..65791e4 100644
--- a/runtime/vm/compilation_trace.cc
+++ b/runtime/vm/compilation_trace.cc
@@ -472,6 +472,7 @@
     : thread_(thread),
       zone_(thread->zone()),
       stream_(nullptr),
+      cid_map_(nullptr),
       uri_(String::Handle(zone_)),
       lib_(Library::Handle(zone_)),
       cls_name_(String::Handle(zone_)),
@@ -490,6 +491,10 @@
           GrowableObjectArray::Handle(zone_, GrowableObjectArray::New())),
       error_(Error::Handle(zone_)) {}
 
+TypeFeedbackLoader::~TypeFeedbackLoader() {
+  delete[] cid_map_;
+}
+
 RawObject* TypeFeedbackLoader::LoadFeedback(ReadStream* stream) {
   stream_ = stream;
 
diff --git a/runtime/vm/compilation_trace.h b/runtime/vm/compilation_trace.h
index 106dbbe..699f08c 100644
--- a/runtime/vm/compilation_trace.h
+++ b/runtime/vm/compilation_trace.h
@@ -85,6 +85,7 @@
 class TypeFeedbackLoader : public ValueObject {
  public:
   explicit TypeFeedbackLoader(Thread* thread);
+  ~TypeFeedbackLoader();
 
   RawObject* LoadFeedback(ReadStream* stream);