{"action":"created","comment":{"url":"https://api.github.com/repos/iojs/io.js/pulls/comments/25556344","id":25556344,"diff_hunk":"@@ -3817,22 +3794,67 @@ int Start(int argc, char** argv) {\n           more = true;\n       }\n     } while (more == true);\n-    code = EmitExit(env);\n+\n+    int exit_code = EmitExit(env);\n+    if (instance_data->is_main())\n+      instance_data->set_exit_code(exit_code);\n     RunAtExit(env);\n \n     env->Dispose();\n     env = nullptr;\n   }\n \n-  CHECK_NE(node_isolate, nullptr);\n-  node_isolate->Dispose();\n-  node_isolate = nullptr;\n+  CHECK_NE(isolate, nullptr);\n+  isolate->Dispose();\n+  isolate = nullptr;\n+\n+  // Main node instance uses uv_default_loop.\n+  if (instance_data->is_worker())\n+    uv_loop_delete(instance_data->loop());\n+}\n+\n+int Start(int argc, char** argv) {\n+  PlatformInit();\n+\n+  const char* replaceInvalid = secure_getenv(\"NODE_INVALID_UTF8\");\n+\n+  if (replaceInvalid == nullptr)\n+    WRITE_UTF8_FLAGS |= String::REPLACE_INVALID_UTF8;\n+\n+  CHECK_GT(argc, 0);\n+\n+  // Hack around with the argv pointer. Used for process.title = \"blah\".\n+  argv = uv_setup_args(argc, argv);\n+\n+  // This needs to run *before* V8::Initialize().  The const_cast is not\n+  // optional, in case you're wondering.\n+  int exec_argc;\n+  const char** exec_argv;\n+  Init(&argc, const_cast<const char**>(argv), &exec_argc, &exec_argv);\n+\n+#if HAVE_OPENSSL\n+  // V8 on Windows doesn't have a good source of entropy. Seed it from\n+  // OpenSSL's pool.\n+  V8::SetEntropySource(crypto::EntropySource);\n+#endif\n+\n+  V8::InitializePlatform(new Platform(4));\n+  V8::Initialize();\n+\n+  NodeInstanceData instance_data(NodeInstanceType::MAIN,\n+                                      uv_default_loop(),\n+                                      argc,\n+                                      const_cast<const char**>(argv),\n+                                      exec_argc,\n+                                      exec_argv);\n+  StartNodeInstance(&instance_data);\n+  int exit_code = instance_data.exit_code();\n   V8::Dispose();\n \n   delete[] exec_argv;\n   exec_argv = nullptr;","path":"src/node.cc","position":151,"original_position":151,"commit_id":"31313f132be3fdcf953674c788da6180b680495c","original_commit_id":"31313f132be3fdcf953674c788da6180b680495c","user":{"login":"bnoordhuis","id":275871,"avatar_url":"https://avatars.githubusercontent.com/u/275871?v=3","gravatar_id":"","url":"https://api.github.com/users/bnoordhuis","html_url":"https://github.com/bnoordhuis","followers_url":"https://api.github.com/users/bnoordhuis/followers","following_url":"https://api.github.com/users/bnoordhuis/following{/other_user}","gists_url":"https://api.github.com/users/bnoordhuis/gists{/gist_id}","starred_url":"https://api.github.com/users/bnoordhuis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bnoordhuis/subscriptions","organizations_url":"https://api.github.com/users/bnoordhuis/orgs","repos_url":"https://api.github.com/users/bnoordhuis/repos","events_url":"https://api.github.com/users/bnoordhuis/events{/privacy}","received_events_url":"https://api.github.com/users/bnoordhuis/received_events","type":"User","site_admin":false},"body":"There is a potential use-after-free waiting to happen here in that exec_argv has been freed now but instance_data still retains a pointer.  I suggest putting instance_data and the call to StartNodeInstance() in a block scope to make that impossible.","created_at":"2015-02-28T10:55:45Z","updated_at":"2015-02-28T10:55:45Z","html_url":"https://github.com/iojs/io.js/pull/980#discussion_r25556344","pull_request_url":"https://api.github.com/repos/iojs/io.js/pulls/980","_links":{"self":{"href":"https://api.github.com/repos/iojs/io.js/pulls/comments/25556344"},"html":{"href":"https://github.com/iojs/io.js/pull/980#discussion_r25556344"},"pull_request":{"href":"https://api.github.com/repos/iojs/io.js/pulls/980"}}},"pull_request":{"url":"https://api.github.com/repos/iojs/io.js/pulls/980","id":30132004,"html_url":"https://github.com/iojs/io.js/pull/980","diff_url":"https://github.com/iojs/io.js/pull/980.diff","patch_url":"https://github.com/iojs/io.js/pull/980.patch","issue_url":"https://api.github.com/repos/iojs/io.js/issues/980","number":980,"state":"open","locked":false,"title":"node: extract node env initialization out of process initialization","user":{"login":"petkaantonov","id":829734,"avatar_url":"https://avatars.githubusercontent.com/u/829734?v=3","gravatar_id":"","url":"https://api.github.com/users/petkaantonov","html_url":"https://github.com/petkaantonov","followers_url":"https://api.github.com/users/petkaantonov/followers","following_url":"https://api.github.com/users/petkaantonov/following{/other_user}","gists_url":"https://api.github.com/users/petkaantonov/gists{/gist_id}","starred_url":"https://api.github.com/users/petkaantonov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petkaantonov/subscriptions","organizations_url":"https://api.github.com/users/petkaantonov/orgs","repos_url":"https://api.github.com/users/petkaantonov/repos","events_url":"https://api.github.com/users/petkaantonov/events{/privacy}","received_events_url":"https://api.github.com/users/petkaantonov/received_events","type":"User","site_admin":false},"body":"This will enable implementing a worker class that is backed by a thread instead of a separate process.\r\n\r\n/cc @bnoordhuis\r\n\r\nP.S. I saw your todo comments about using uv_default_loop, I was thinking why not have the main thread use the default loop and workers use their own loops?","created_at":"2015-02-27T00:40:42Z","updated_at":"2015-02-28T10:55:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0924867f0c3e9dc1b4310ff518b5c9cbf6ff29bd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/iojs/io.js/pulls/980/commits","review_comments_url":"https://api.github.com/repos/iojs/io.js/pulls/980/comments","review_comment_url":"https://api.github.com/repos/iojs/io.js/pulls/comments{/number}","comments_url":"https://api.github.com/repos/iojs/io.js/issues/980/comments","statuses_url":"https://api.github.com/repos/iojs/io.js/statuses/31313f132be3fdcf953674c788da6180b680495c","head":{"label":"petkaantonov:threadstuffs","ref":"threadstuffs","sha":"31313f132be3fdcf953674c788da6180b680495c","user":{"login":"petkaantonov","id":829734,"avatar_url":"https://avatars.githubusercontent.com/u/829734?v=3","gravatar_id":"","url":"https://api.github.com/users/petkaantonov","html_url":"https://github.com/petkaantonov","followers_url":"https://api.github.com/users/petkaantonov/followers","following_url":"https://api.github.com/users/petkaantonov/following{/other_user}","gists_url":"https://api.github.com/users/petkaantonov/gists{/gist_id}","starred_url":"https://api.github.com/users/petkaantonov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petkaantonov/subscriptions","organizations_url":"https://api.github.com/users/petkaantonov/orgs","repos_url":"https://api.github.com/users/petkaantonov/repos","events_url":"https://api.github.com/users/petkaantonov/events{/privacy}","received_events_url":"https://api.github.com/users/petkaantonov/received_events","type":"User","site_admin":false},"repo":{"id":30495325,"name":"io.js","full_name":"petkaantonov/io.js","owner":{"login":"petkaantonov","id":829734,"avatar_url":"https://avatars.githubusercontent.com/u/829734?v=3","gravatar_id":"","url":"https://api.github.com/users/petkaantonov","html_url":"https://github.com/petkaantonov","followers_url":"https://api.github.com/users/petkaantonov/followers","following_url":"https://api.github.com/users/petkaantonov/following{/other_user}","gists_url":"https://api.github.com/users/petkaantonov/gists{/gist_id}","starred_url":"https://api.github.com/users/petkaantonov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petkaantonov/subscriptions","organizations_url":"https://api.github.com/users/petkaantonov/orgs","repos_url":"https://api.github.com/users/petkaantonov/repos","events_url":"https://api.github.com/users/petkaantonov/events{/privacy}","received_events_url":"https://api.github.com/users/petkaantonov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/petkaantonov/io.js","description":"A friendly fork of Node.js with an open governance model","fork":true,"url":"https://api.github.com/repos/petkaantonov/io.js","forks_url":"https://api.github.com/repos/petkaantonov/io.js/forks","keys_url":"https://api.github.com/repos/petkaantonov/io.js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/petkaantonov/io.js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/petkaantonov/io.js/teams","hooks_url":"https://api.github.com/repos/petkaantonov/io.js/hooks","issue_events_url":"https://api.github.com/repos/petkaantonov/io.js/issues/events{/number}","events_url":"https://api.github.com/repos/petkaantonov/io.js/events","assignees_url":"https://api.github.com/repos/petkaantonov/io.js/assignees{/user}","branches_url":"https://api.github.com/repos/petkaantonov/io.js/branches{/branch}","tags_url":"https://api.github.com/repos/petkaantonov/io.js/tags","blobs_url":"https://api.github.com/repos/petkaantonov/io.js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/petkaantonov/io.js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/petkaantonov/io.js/git/refs{/sha}","trees_url":"https://api.github.com/repos/petkaantonov/io.js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/petkaantonov/io.js/statuses/{sha}","languages_url":"https://api.github.com/repos/petkaantonov/io.js/languages","stargazers_url":"https://api.github.com/repos/petkaantonov/io.js/stargazers","contributors_url":"https://api.github.com/repos/petkaantonov/io.js/contributors","subscribers_url":"https://api.github.com/repos/petkaantonov/io.js/subscribers","subscription_url":"https://api.github.com/repos/petkaantonov/io.js/subscription","commits_url":"https://api.github.com/repos/petkaantonov/io.js/commits{/sha}","git_commits_url":"https://api.github.com/repos/petkaantonov/io.js/git/commits{/sha}","comments_url":"https://api.github.com/repos/petkaantonov/io.js/comments{/number}","issue_comment_url":"https://api.github.com/repos/petkaantonov/io.js/issues/comments{/number}","contents_url":"https://api.github.com/repos/petkaantonov/io.js/contents/{+path}","compare_url":"https://api.github.com/repos/petkaantonov/io.js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/petkaantonov/io.js/merges","archive_url":"https://api.github.com/repos/petkaantonov/io.js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/petkaantonov/io.js/downloads","issues_url":"https://api.github.com/repos/petkaantonov/io.js/issues{/number}","pulls_url":"https://api.github.com/repos/petkaantonov/io.js/pulls{/number}","milestones_url":"https://api.github.com/repos/petkaantonov/io.js/milestones{/number}","notifications_url":"https://api.github.com/repos/petkaantonov/io.js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/petkaantonov/io.js/labels{/name}","releases_url":"https://api.github.com/repos/petkaantonov/io.js/releases{/id}","created_at":"2015-02-08T15:30:16Z","updated_at":"2015-02-08T15:30:19Z","pushed_at":"2015-02-27T03:43:25Z","git_url":"git://github.com/petkaantonov/io.js.git","ssh_url":"git@github.com:petkaantonov/io.js.git","clone_url":"https://github.com/petkaantonov/io.js.git","svn_url":"https://github.com/petkaantonov/io.js","homepage":"https://iojs.org","size":120086,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"v1.x"}},"base":{"label":"iojs:v1.x","ref":"v1.x","sha":"ae7a23351f7e5b06ab88b7ea9c18d7c5b2e287e9","user":{"login":"iojs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/iojs","html_url":"https://github.com/iojs","followers_url":"https://api.github.com/users/iojs/followers","following_url":"https://api.github.com/users/iojs/following{/other_user}","gists_url":"https://api.github.com/users/iojs/gists{/gist_id}","starred_url":"https://api.github.com/users/iojs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iojs/subscriptions","organizations_url":"https://api.github.com/users/iojs/orgs","repos_url":"https://api.github.com/users/iojs/repos","events_url":"https://api.github.com/users/iojs/events{/privacy}","received_events_url":"https://api.github.com/users/iojs/received_events","type":"Organization","site_admin":false},"repo":{"id":27193779,"name":"io.js","full_name":"iojs/io.js","owner":{"login":"iojs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/iojs","html_url":"https://github.com/iojs","followers_url":"https://api.github.com/users/iojs/followers","following_url":"https://api.github.com/users/iojs/following{/other_user}","gists_url":"https://api.github.com/users/iojs/gists{/gist_id}","starred_url":"https://api.github.com/users/iojs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iojs/subscriptions","organizations_url":"https://api.github.com/users/iojs/orgs","repos_url":"https://api.github.com/users/iojs/repos","events_url":"https://api.github.com/users/iojs/events{/privacy}","received_events_url":"https://api.github.com/users/iojs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/iojs/io.js","description":"A friendly fork of Node.js with an open governance model","fork":false,"url":"https://api.github.com/repos/iojs/io.js","forks_url":"https://api.github.com/repos/iojs/io.js/forks","keys_url":"https://api.github.com/repos/iojs/io.js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/iojs/io.js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/iojs/io.js/teams","hooks_url":"https://api.github.com/repos/iojs/io.js/hooks","issue_events_url":"https://api.github.com/repos/iojs/io.js/issues/events{/number}","events_url":"https://api.github.com/repos/iojs/io.js/events","assignees_url":"https://api.github.com/repos/iojs/io.js/assignees{/user}","branches_url":"https://api.github.com/repos/iojs/io.js/branches{/branch}","tags_url":"https://api.github.com/repos/iojs/io.js/tags","blobs_url":"https://api.github.com/repos/iojs/io.js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/iojs/io.js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/iojs/io.js/git/refs{/sha}","trees_url":"https://api.github.com/repos/iojs/io.js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/iojs/io.js/statuses/{sha}","languages_url":"https://api.github.com/repos/iojs/io.js/languages","stargazers_url":"https://api.github.com/repos/iojs/io.js/stargazers","contributors_url":"https://api.github.com/repos/iojs/io.js/contributors","subscribers_url":"https://api.github.com/repos/iojs/io.js/subscribers","subscription_url":"https://api.github.com/repos/iojs/io.js/subscription","commits_url":"https://api.github.com/repos/iojs/io.js/commits{/sha}","git_commits_url":"https://api.github.com/repos/iojs/io.js/git/commits{/sha}","comments_url":"https://api.github.com/repos/iojs/io.js/comments{/number}","issue_comment_url":"https://api.github.com/repos/iojs/io.js/issues/comments{/number}","contents_url":"https://api.github.com/repos/iojs/io.js/contents/{+path}","compare_url":"https://api.github.com/repos/iojs/io.js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/iojs/io.js/merges","archive_url":"https://api.github.com/repos/iojs/io.js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/iojs/io.js/downloads","issues_url":"https://api.github.com/repos/iojs/io.js/issues{/number}","pulls_url":"https://api.github.com/repos/iojs/io.js/pulls{/number}","milestones_url":"https://api.github.com/repos/iojs/io.js/milestones{/number}","notifications_url":"https://api.github.com/repos/iojs/io.js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/iojs/io.js/labels{/name}","releases_url":"https://api.github.com/repos/iojs/io.js/releases{/id}","created_at":"2014-11-26T19:57:11Z","updated_at":"2015-02-28T10:28:24Z","pushed_at":"2015-02-28T06:04:26Z","git_url":"git://github.com/iojs/io.js.git","ssh_url":"git@github.com:iojs/io.js.git","clone_url":"https://github.com/iojs/io.js.git","svn_url":"https://github.com/iojs/io.js","homepage":"https://iojs.org","size":153170,"stargazers_count":10682,"watchers_count":10682,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":675,"mirror_url":null,"open_issues_count":178,"forks":675,"open_issues":178,"watchers":10682,"default_branch":"v1.x"}},"_links":{"self":{"href":"https://api.github.com/repos/iojs/io.js/pulls/980"},"html":{"href":"https://github.com/iojs/io.js/pull/980"},"issue":{"href":"https://api.github.com/repos/iojs/io.js/issues/980"},"comments":{"href":"https://api.github.com/repos/iojs/io.js/issues/980/comments"},"review_comments":{"href":"https://api.github.com/repos/iojs/io.js/pulls/980/comments"},"review_comment":{"href":"https://api.github.com/repos/iojs/io.js/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/iojs/io.js/pulls/980/commits"},"statuses":{"href":"https://api.github.com/repos/iojs/io.js/statuses/31313f132be3fdcf953674c788da6180b680495c"}}}}