From 7306b0f73360272fc5a8e4b3953aec8a024698f2 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Mon, 3 Apr 2023 12:37:49 +0530 Subject: [PATCH] sea: fix memory leak detected by asan Signed-off-by: Darshan Sen PR-URL: https://github.com/nodejs/node/pull/47309 Reviewed-By: Yagiz Nizipli Reviewed-By: Colin Ihrig Reviewed-By: Mohammed Keyvanzadeh Reviewed-By: Joyee Cheung Reviewed-By: Michael Dawson Reviewed-By: James M Snell --- src/node_sea.cc | 20 +++++++------------ .../test-single-executable-application.js | 3 --- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/node_sea.cc b/src/node_sea.cc index 18b661ce4ff31d..fa7fb86b0ed05c 100644 --- a/src/node_sea.cc +++ b/src/node_sea.cc @@ -91,19 +91,13 @@ std::tuple FixupArgsForSEA(int argc, char** argv) { // Repeats argv[0] at position 1 on argv as a replacement for the missing // entry point file path. if (IsSingleExecutable()) { - char** new_argv = new char*[argc + 2]; - int new_argc = 0; - new_argv[new_argc++] = argv[0]; - new_argv[new_argc++] = argv[0]; - - for (int i = 1; i < argc; ++i) { - new_argv[new_argc++] = argv[i]; - } - - new_argv[new_argc] = nullptr; - - argc = new_argc; - argv = new_argv; + static std::vector new_argv; + new_argv.reserve(argc + 2); + new_argv.emplace_back(argv[0]); + new_argv.insert(new_argv.end(), argv, argv + argc); + new_argv.emplace_back(nullptr); + argc = new_argv.size() - 1; + argv = new_argv.data(); } return {argc, argv}; diff --git a/test/parallel/test-single-executable-application.js b/test/parallel/test-single-executable-application.js index f41b9d7778d7d3..01329ff2ae46a0 100644 --- a/test/parallel/test-single-executable-application.js +++ b/test/parallel/test-single-executable-application.js @@ -16,9 +16,6 @@ if (!process.config.variables.single_executable_application) if (!['darwin', 'win32', 'linux'].includes(process.platform)) common.skip(`Unsupported platform ${process.platform}.`); -if (process.platform === 'linux' && process.config.variables.asan) - common.skip('Running the resultant binary fails with `Segmentation fault (core dumped)`.'); - if (process.platform === 'linux' && process.config.variables.is_debug === 1) common.skip('Running the resultant binary fails with `Couldn\'t read target executable"`.');