src: fix memory leak in CreateEnvironment when bootstrap fails

PR-URL: https://github.com/nodejs/node/pull/30467
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
diff --git a/src/api/environment.cc b/src/api/environment.cc
index 02e9991..23bae50 100644
--- a/src/api/environment.cc
+++ b/src/api/environment.cc
@@ -349,8 +349,10 @@
                                       Environment::kOwnsProcessState |
                                       Environment::kOwnsInspector));
   env->InitializeLibuv(per_process::v8_is_profiling);
-  if (env->RunBootstrapping().IsEmpty())
+  if (env->RunBootstrapping().IsEmpty()) {
+    FreeEnvironment(env);
     return nullptr;
+  }
   return env;
 }