fix: memory leak when scanning sketchbooks with large files (#2555)

Resolves https://github.com/arduino/arduino-ide/issues/2537

Fix memory leak issue caused by inflight dependency, see https://github.com/isaacs/node-glob/issues/435
This commit is contained in:
Giacomo Cusinato
2024-11-21 08:40:52 +01:00
committed by GitHub
parent d6235f0a0c
commit 7c231fff76
5 changed files with 243 additions and 93 deletions

View File

@@ -5,7 +5,7 @@
const path = require('node:path');
const { mkdirSync, promises: fs, rmSync } = require('node:fs');
const { exec } = require('./utils');
const glob = require('glob');
const { glob } = require('glob');
const { SemVer, gte, valid: validSemVer } = require('semver');
// Use a node-protoc fork until apple arm32 is supported
// https://github.com/YePpHa/node-protoc/pull/10
@@ -147,16 +147,14 @@
rmSync(out, { recursive: true, maxRetries: 5, force: true });
mkdirSync(out, { recursive: true });
const protos = await new Promise((resolve) =>
glob('**/*.proto', { cwd: rpc }, (error, matches) => {
if (error) {
console.log(error.stack ?? error.message);
resolve([]);
return;
}
resolve(matches.map((filename) => path.join(rpc, filename)));
})
);
let protos = [];
try {
const matches = await glob('**/*.proto', { cwd: rpc });
protos = matches.map((filename) => path.join(rpc, filename));
} catch (error) {
console.log(error.stack ?? error.message);
}
if (!protos || protos.length === 0) {
console.log(`Could not find any .proto files under ${rpc}.`);
process.exit(1);