Skip to content

Commit 5f4fead

Browse files
committed
fix: memory leak introduced in [email protected]
fixes #12
1 parent 0163764 commit 5f4fead

File tree

1 file changed

+85
-86
lines changed

1 file changed

+85
-86
lines changed

index.js

Lines changed: 85 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,103 +1295,101 @@ class Tangerine extends dns.promises.Resolver {
12951295
},
12961296
{ once: true }
12971297
);
1298-
} finally {
1299-
this.#releaseAbortController(abortController);
1300-
}
1301-
// wrap with try/catch because ENODATA shouldn't cause errors
1302-
try {
1303-
switch (type) {
1304-
case 'A': {
1305-
const result = await this.resolve4(
1306-
name,
1307-
{ ...options, ttl: true },
1308-
abortController
1309-
);
1310-
return result.map((r) => ({ type, ...r }));
1311-
}
1298+
// wrap with try/catch because ENODATA shouldn't cause errors
1299+
try {
1300+
switch (type) {
1301+
case 'A': {
1302+
const result = await this.resolve4(
1303+
name,
1304+
{ ...options, ttl: true },
1305+
abortController
1306+
);
1307+
return result.map((r) => ({ type, ...r }));
1308+
}
13121309

1313-
case 'AAAA': {
1314-
const result = await this.resolve6(
1315-
name,
1316-
{ ...options, ttl: true },
1317-
abortController
1318-
);
1319-
return result.map((r) => ({ type, ...r }));
1320-
}
1310+
case 'AAAA': {
1311+
const result = await this.resolve6(
1312+
name,
1313+
{ ...options, ttl: true },
1314+
abortController
1315+
);
1316+
return result.map((r) => ({ type, ...r }));
1317+
}
13211318

1322-
case 'CNAME': {
1323-
const result = await this.resolveCname(
1324-
name,
1325-
options,
1326-
abortController
1327-
);
1328-
return result.map((value) => ({ type, value }));
1329-
}
1319+
case 'CNAME': {
1320+
const result = await this.resolveCname(
1321+
name,
1322+
options,
1323+
abortController
1324+
);
1325+
return result.map((value) => ({ type, value }));
1326+
}
13301327

1331-
case 'MX': {
1332-
const result = await this.resolveMx(name, options, abortController);
1333-
return result.map((r) => ({ type, ...r }));
1334-
}
1328+
case 'MX': {
1329+
const result = await this.resolveMx(name, options, abortController);
1330+
return result.map((r) => ({ type, ...r }));
1331+
}
13351332

1336-
case 'NAPTR': {
1337-
const result = await this.resolveNaptr(
1338-
name,
1339-
options,
1340-
abortController
1341-
);
1342-
return result.map((value) => ({ type, value }));
1343-
}
1333+
case 'NAPTR': {
1334+
const result = await this.resolveNaptr(
1335+
name,
1336+
options,
1337+
abortController
1338+
);
1339+
return result.map((value) => ({ type, value }));
1340+
}
13441341

1345-
case 'NS': {
1346-
const result = await this.resolveNs(name, options, abortController);
1347-
return result.map((value) => ({ type, value }));
1348-
}
1342+
case 'NS': {
1343+
const result = await this.resolveNs(name, options, abortController);
1344+
return result.map((value) => ({ type, value }));
1345+
}
13491346

1350-
case 'PTR': {
1351-
const result = await this.resolvePtr(
1352-
name,
1353-
options,
1354-
abortController
1355-
);
1356-
return result.map((value) => ({ type, value }));
1357-
}
1347+
case 'PTR': {
1348+
const result = await this.resolvePtr(
1349+
name,
1350+
options,
1351+
abortController
1352+
);
1353+
return result.map((value) => ({ type, value }));
1354+
}
13581355

1359-
case 'SOA': {
1360-
const result = await this.resolveSoa(
1361-
name,
1362-
options,
1363-
abortController
1364-
);
1365-
return { type, ...result };
1366-
}
1356+
case 'SOA': {
1357+
const result = await this.resolveSoa(
1358+
name,
1359+
options,
1360+
abortController
1361+
);
1362+
return { type, ...result };
1363+
}
13671364

1368-
case 'SRV': {
1369-
const result = await this.resolveSrv(
1370-
name,
1371-
options,
1372-
abortController
1373-
);
1374-
return result.map((value) => ({ type, value }));
1375-
}
1365+
case 'SRV': {
1366+
const result = await this.resolveSrv(
1367+
name,
1368+
options,
1369+
abortController
1370+
);
1371+
return result.map((value) => ({ type, value }));
1372+
}
13761373

1377-
case 'TXT': {
1378-
const result = await this.resolveTxt(
1379-
name,
1380-
options,
1381-
abortController
1382-
);
1383-
return result.map((entries) => ({ type, entries }));
1384-
}
1374+
case 'TXT': {
1375+
const result = await this.resolveTxt(
1376+
name,
1377+
options,
1378+
abortController
1379+
);
1380+
return result.map((entries) => ({ type, entries }));
1381+
}
13851382

1386-
default: {
1387-
break;
1383+
default: {
1384+
break;
1385+
}
13881386
}
1389-
}
1390-
} catch (err) {
1391-
debug(err);
1387+
} catch (err) {
1388+
debug(err);
13921389

1393-
if (err.code === dns.NODATA) return;
1394-
throw err;
1390+
if (err.code === dns.NODATA) return;
1391+
throw err;
1392+
}
13951393
} finally {
13961394
this.#releaseAbortController(abortController);
13971395
}
@@ -1421,8 +1419,9 @@ class Tangerine extends dns.promises.Resolver {
14211419
this.constructor.ANY_TYPES.length,
14221420
abortController.signal
14231421
);
1424-
} finally {
1422+
} catch (err) {
14251423
this.#releaseAbortController(abortController);
1424+
throw err;
14261425
}
14271426
}
14281427

0 commit comments

Comments
 (0)