From fc8b069af032cc8abb442f5b9956dc04247bb764 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Sun, 29 Mar 2026 07:27:04 -0500 Subject: [PATCH] Close opened file handles from the vCard lexer. --- src/vcard.nim | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/vcard.nim b/src/vcard.nim index 1500a78..acb28c0 100644 --- a/src/vcard.nim +++ b/src/vcard.nim @@ -65,17 +65,27 @@ proc readVCard*(p: var VCardParser, validate = true): VCard = p.error(exc.msg) proc initVCardParser*(input: Stream, filename = "input"): VCardParser = + ## Note: the returned VCardParser object will have an open file handle. Make + ## sure to call `close` on the returned VCardParser to avoid file handle + ## leaks. result.filename = filename lexer.open(result, input) proc initVCardParser*(content: string, filename = "input"): VCardParser = + ## Note: the returned VCardParser object will have an open file handle. Make + ## sure to call `close` on the returned VCardParser to avoid file handle + ## leaks. initVCardParser(newStringStream(content), filename) proc initVCardParserFromFile*(filepath: string): VCardParser = + ## Note: the returned VCardParser object will have an open file handle. Make + ## sure to call `close` on the returned VCardParser to avoid file handle + ## leaks. initVCardParser(newFileStream(filepath, fmRead), filepath) proc parseVCards*(input: Stream, filename = "input", validate = true): seq[VCard] = var p = initVCardParser(input, filename) + defer: p.close() while p.peek != '\0': result.add(p.readVCard(validate)) proc parseVCards*(content: string, filename = "input", validate = true): seq[VCard] =