Skip to content

Commit

Permalink
fix: close handles before returning
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyg603 committed Sep 16, 2023
1 parent bebe24a commit e964e24
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/pdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class PdbFile {
}

let fileHandle: FileHandle;

let pdbFile: PdbFile;
try {
fileHandle = await open(pdbFilePath, 'r');

Expand Down Expand Up @@ -69,10 +69,12 @@ export class PdbFile {
}

const guid = new PdbGuid(guid_d1, guid_d2, guid_d3, guid_d4, age);
return new PdbFile(guid);
pdbFile = new PdbFile(guid);
} finally {
await fileHandle!?.close();
}

return pdbFile;
}

private static async getGuidBytesFromPdbStream(root: PdbRootStream, fileHandle: FileHandle): Promise<Uint8Array> {
Expand Down
6 changes: 4 additions & 2 deletions src/pe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class PeFile {
}

let fileHandle: FileHandle;

let peFile: PeFile;
try {
fileHandle = await open(peFilePath, 'r');

Expand Down Expand Up @@ -62,9 +62,11 @@ export class PeFile {
}

const guid = new PeGuid(timeStamp, sizeOfImage);
return new PeFile(guid);
peFile = new PeFile(guid);
} finally {
await fileHandle!?.close();
}

return peFile;
}
}
7 changes: 5 additions & 2 deletions src/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class PdbRootStream {
return uints;
}

static async createFromFile(filePath: string): Promise<PdbRootStream | null> {
static async createFromFile(filePath: string): Promise<PdbRootStream> {
// LLVM.org refers to the first section of the file as The Superblock
// At file offset 0 in an MSF file is the MSF SuperBlock, which is laid out as follows:
//
Expand All @@ -64,6 +64,7 @@ export class PdbRootStream {
// ulittle32_t BlockMapAddr;
// };
let fileHandle: FileHandle;
let pdbRootStream: PdbRootStream;
try {
const fileHandle = await open(filePath, 'r');

Expand Down Expand Up @@ -122,10 +123,12 @@ export class PdbRootStream {
streamDirectory[i] = getStreamBytesAsNumber(rootPageData, i);
}

return new PdbRootStream(blockSize, directoryBytesLength, streamDirectory);
pdbRootStream = new PdbRootStream(blockSize, directoryBytesLength, streamDirectory);
} finally {
fileHandle!?.close();
}

return pdbRootStream;
}
}

Expand Down

0 comments on commit e964e24

Please sign in to comment.