Skip to content

Commit 7306b0f

Browse files
RaisinTenMoLow
authored andcommitted
sea: fix memory leak detected by asan
Signed-off-by: Darshan Sen <[email protected]> PR-URL: nodejs#47309 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 3924893 commit 7306b0f

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

src/node_sea.cc

+7-13
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,13 @@ std::tuple<int, char**> FixupArgsForSEA(int argc, char** argv) {
9191
// Repeats argv[0] at position 1 on argv as a replacement for the missing
9292
// entry point file path.
9393
if (IsSingleExecutable()) {
94-
char** new_argv = new char*[argc + 2];
95-
int new_argc = 0;
96-
new_argv[new_argc++] = argv[0];
97-
new_argv[new_argc++] = argv[0];
98-
99-
for (int i = 1; i < argc; ++i) {
100-
new_argv[new_argc++] = argv[i];
101-
}
102-
103-
new_argv[new_argc] = nullptr;
104-
105-
argc = new_argc;
106-
argv = new_argv;
94+
static std::vector<char*> new_argv;
95+
new_argv.reserve(argc + 2);
96+
new_argv.emplace_back(argv[0]);
97+
new_argv.insert(new_argv.end(), argv, argv + argc);
98+
new_argv.emplace_back(nullptr);
99+
argc = new_argv.size() - 1;
100+
argv = new_argv.data();
107101
}
108102

109103
return {argc, argv};

test/parallel/test-single-executable-application.js

-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ if (!process.config.variables.single_executable_application)
1616
if (!['darwin', 'win32', 'linux'].includes(process.platform))
1717
common.skip(`Unsupported platform ${process.platform}.`);
1818

19-
if (process.platform === 'linux' && process.config.variables.asan)
20-
common.skip('Running the resultant binary fails with `Segmentation fault (core dumped)`.');
21-
2219
if (process.platform === 'linux' && process.config.variables.is_debug === 1)
2320
common.skip('Running the resultant binary fails with `Couldn\'t read target executable"`.');
2421

0 commit comments

Comments
 (0)