Skip to content

Commit 33b0906

Browse files
RaisinTenRafaelGSS
authored andcommitted
sea: fix memory leak detected by asan
Signed-off-by: Darshan Sen <[email protected]> PR-URL: #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 910d296 commit 33b0906

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
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

-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +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-
// Source of the memory leak - https://github.com/nodejs/node/blob/da0bc6db98cef98686122ea1e2cd2dbd2f52d123/src/node_sea.cc#L94.
21-
common.skip('Running the resultant binary fails because of a memory leak ASAN error.');
22-
}
23-
2419
if (process.platform === 'linux' && process.config.variables.is_debug === 1)
2520
common.skip('Running the resultant binary fails with `Couldn\'t read target executable"`.');
2621

0 commit comments

Comments
 (0)