[VM] Free the current working directory string if we happen to re-initialize the VM

This is an attempt to fix a flakily reported ASAN leak of the form:

  Direct leak of 28 byte(s) in 1 object(s) allocated from:
      #0 0x55827f0dacf2 in __interceptor_realloc /b/s/w/ir/kitchen-workdir/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cc:107:3
      #1 0x7f52fe7a41ca in getcwd (/lib/x86_64-linux-gnu/libc.so.6+0xf01ca)

  SUMMARY: AddressSanitizer: 28 byte(s) leaked in 1 allocation(s).
Change-Id: I7c76be43eecd2c445631af22a93c710df93379f4
Reviewed-on: https://dart-review.googlesource.com/c/85562
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
diff --git a/runtime/bin/dartutils.cc b/runtime/bin/dartutils.cc
index 6eade2f..cf75b68 100644
--- a/runtime/bin/dartutils.cc
+++ b/runtime/bin/dartutils.cc
@@ -783,8 +783,13 @@
 }
 
 bool DartUtils::SetOriginalWorkingDirectory() {
+  // If we happen to re-initialize the Dart VM multiple times, make sure to free
+  // the old string (allocated by getcwd()) before setting a new one.
+  if (original_working_directory != nullptr) {
+    free(const_cast<char*>(original_working_directory));
+  }
   original_working_directory = Directory::CurrentNoScope();
-  return original_working_directory != NULL;
+  return original_working_directory != nullptr;
 }
 
 Dart_Handle DartUtils::GetCanonicalizableWorkingDirectory() {