[VM/Runtime] - Address some bot failrues reported in https://github.com/dart-lang/sdk/issues/46922

- Fix ASAN leak detected error
- Add error when kernel isolate is unable to create native rep[y port

TEST=cq

Change-Id: Ibafebc7ea5eac5ffc7fe2816ac9683b31f9329ae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210302
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc
index 5b0bc2b..fc1877f 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -9396,9 +9396,10 @@
         ml.Notify();
       }
       count++;
+    } else {
+      free(error);
     }
   } while (count < 100);
-  free(error);
 }
 
 TEST_CASE(DartAPI_InvokeVMServiceMethod_Loop) {
diff --git a/runtime/vm/kernel_isolate.cc b/runtime/vm/kernel_isolate.cc
index 066c7d4..5d41659 100644
--- a/runtime/vm/kernel_isolate.cc
+++ b/runtime/vm/kernel_isolate.cc
@@ -436,7 +436,6 @@
                                  false)),
         next_(NULL),
         prev_(NULL) {
-    ASSERT(port_ != ILLEGAL_PORT);
     RegisterRequest(this);
     result_.status = Dart_KernelCompilationStatus_Unknown;
     result_.error = NULL;
@@ -446,7 +445,9 @@
 
   ~KernelCompilationRequest() {
     UnregisterRequest(this);
-    Dart_CloseNativePort(port_);
+    if (port_ != ILLEGAL_PORT) {
+      Dart_CloseNativePort(port_);
+    }
   }
 
   intptr_t setDillData(Dart_CObject** dills_array,
@@ -481,6 +482,13 @@
       char const* klass,
       bool is_static,
       const MallocGrowableArray<char*>* experimental_flags) {
+    if (port_ == ILLEGAL_PORT) {
+      Dart_KernelCompilationResult result = {};
+      result.status = Dart_KernelCompilationStatus_Unknown;
+      result.error =
+          Utils::StrDup("Error Kernel Isolate : unable to create reply port");
+      return result;
+    }
     Thread* thread = Thread::Current();
     TransitionNativeToVM transition(thread);
     Dart_CObject tag;