SwiftDocOrg / CommonMark

Create, parse, and render Markdown text according to the CommonMark specification
MIT License
179 stars 10 forks source link

Fix memory leaks #22

Closed regexident closed 3 years ago

regexident commented 3 years ago

Fixes a memory leak in Document.init(_:options:), as well as a memory safety bug (dangling pointers) caused by an erroneous implementation of Node.init(from:), which was hidden by the memory leak.

Due to the memory leak caused by never setting self.managed = true on decoding of Document the dangling pointers produced by Node.init(from:) did not cause a crash before.

The previous implementation simply decoded a Document and then pulled its root node out without properly unlinking it from the document and re-assigning the memory management duties. So when the Document gets deinitialized any pointers to its contents are no longer valid (unless the document leaks its contents, which it did).

Fixes https://github.com/SwiftDocOrg/CommonMark/issues/19

regexident commented 3 years ago

FYI: this seems to still need some work. I'm on it, stay tuned (aiming for later today)!

mattt commented 3 years ago

@regexident Thanks for the heads-up. Awesome work so far! I converted this PR to a draft to make sure this doesn't get merged accidentally before it's ready. What else needs to go in?

regexident commented 3 years ago

The remaining issues at hand:

  1. I seem to have messed up a rebase, leaving self.managed = managed, which does nothing (useful, that is), since there is no local binding called managed. A perfect example for why implicit self. is a bug, not a feature. This should not have compiled.
  2. When running the test suite to make sure my fix works and didn't break anything I still had a few print(document) statements sprinkled over the framework, what I had used for poor man's debugging/tracing. With them it worked, but once removed the code crashes. In other words: they were hiding some remaining dangling pointer by extending the lifetime of document.
  3. I found that the buffers returned by cmark_render_commonmark/cmark_render_html/cmark_render_xml/cmark_render_latex/cmark_render_man are never freed, resulting in yet another memory leak.

See latest commits.

regexident commented 3 years ago

With these latest commits pushed this PR should be (almost) ready to review/merge.

I say "almost" since interestingly now the func testInlineElementCodingRoundTrip() test keeps failing with the following:

XCTAssertEqual failed: (
    "<p><a href="https://www.un.org/en/universal-declaration-human-rights/" title="View full version">Universal Declaration of 
    Human Rights</a></p>
    "
) is not equal to (
    "<p><a href="https://www.un.org/en/universal-declaration-human-rights/" title="View full version"></a></p>
    "
)

As you can see the description lacks the title "Universal Declaration of Human Rights" for some weird reason.

So to get an idea of where the fault is I added this to the test method:

print()
print("Initial:", link)
print()
print("Initial title:", link.title as Any)
print()
print("Commonmark:", commonmark)
print()
print("Decoded:", decoded[0])
print()
print("Decoded title:", decoded[0].title as Any)
print()

Which produced the following:

Initial: [Universal Declaration of Human Rights](https://www.un.org/en/universal-declaration-human-rights/ "View full version")

Initial title: Optional("View full version")

Commonmark: ["[Universal Declaration of Human Rights](https:\/\/www.un.org\/en\/universal-declaration-human-rights\/ \"View full version\")\n"]

Decoded: [](https://www.un.org/en/universal-declaration-human-rights/ "View full version")

Decoded title: Optional("View full version")

So it looks like the title gets lost in the decoding somehow. Which is weird, since it's based on the same call to cmark_parse_document that was used to parse the initial document. ๐Ÿค”

But wait, it gets even weirder! ๐Ÿคฏ

If I call let _ = document.render(format: .commonmark) on the decoded document before calling link.description, then the test succeeds. You can even add the call in the document's initializer (which I did to see if it was yet another memory lifetime issue). It's almost like the render materializes the link's title, which other is missing or something? ๐Ÿคจ

Any idea what's going on here, @mattt?

mattt commented 3 years ago

Running the unit tests with Address Sanitizer enabled shows the root cause of the test failure for testInlineElementCodingRoundTrip:

Test Case '-[CommonMarkTests.DocumentCodingTests testInlineElementCodingRoundTrip]' started.
=================================================================
==40289==ERROR: AddressSanitizer: heap-use-after-free on address 0x610000050341 at pc 0x0001001602a0 bp 0x7ffeefbfbff0 sp 0x7ffeefbfb7b8
READ of size 37 at 0x610000050341 thread T0
    #0 0x10016029f in __asan_memcpy+0x1af (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x4729f)
    #1 0x109c768ae in cmark_chunk_to_cstr+0x29e (CommonMarkTests:x86_64+0x6b8ae)
    #2 0x109c765bb in cmark_node_get_literal+0xeb (CommonMarkTests:x86_64+0x6b5bb)
    #3 0x109c50dd5 in S_render_node+0x2065 (CommonMarkTests:x86_64+0x45dd5)
    #4 0x109c7d004 in cmark_render+0xb14 (CommonMarkTests:x86_64+0x72004)
    #5 0x109c4e324 in cmark_render_commonmark+0x44 (CommonMarkTests:x86_64+0x43324)
    #6 0x109ce0785 in Node.render(format:options:width:)+0x5e5 (CommonMarkTests:x86_64+0xd5785)
    #7 0x109ce5662 in Node.description.getter+0x182 (CommonMarkTests:x86_64+0xda662)
    #8 0x109c1e2fe in DocumentCodingTests.testInlineElementCodingRoundTrip() DocumentCodingTests.swift:43
    #9 0x109c1f5a8 in @objc DocumentCodingTests.testInlineElementCodingRoundTrip() <compiler-generated>
    #10 0x7fff2e5e78ab in __invoking___+0x8b (CoreFoundation:x86_64h+0x658ab)
    #11 0x7fff2e5e7750 in -[NSInvocation invoke]+0x12e (CoreFoundation:x86_64h+0x65750)
    #12 0x101075d39 in __24-[XCTestCase invokeTest]_block_invoke_3+0x33 (XCTest:x86_64+0x30d39)
    #13 0x10113e214 in +[XCTSwiftErrorObservation observeErrorsInBlock:]+0x44 (XCTest:x86_64+0xf9214)
    #14 0x101075c3b in __24-[XCTestCase invokeTest]_block_invoke_2+0x76 (XCTest:x86_64+0x30c3b)
    #15 0x101105599 in -[XCTMemoryChecker _assertInvalidObjectsDeallocatedAfterScope:]+0x40 (XCTest:x86_64+0xc0599)
    #16 0x1010808e9 in -[XCTestCase assertInvalidObjectsDeallocatedAfterScope:]+0x3c (XCTest:x86_64+0x3b8e9)
    #17 0x101075b81 in __24-[XCTestCase invokeTest]_block_invoke.231+0xc6 (XCTest:x86_64+0x30b81)
    #18 0x1010ea6d7 in -[XCTestCase(XCTIssueHandling) _caughtUnhandledDeveloperExceptionPermittingControlFlowInterruptions:caughtInterruptionException:whileExecutingBlock:]+0xb2 (XCTest:x86_64+0xa56d7)
    #19 0x101075644 in -[XCTestCase invokeTest]+0x40c (XCTest:x86_64+0x30644)
    #20 0x101077022 in __26-[XCTestCase performTest:]_block_invoke_2+0x2a (XCTest:x86_64+0x32022)
    #21 0x1010ea6d7 in -[XCTestCase(XCTIssueHandling) _caughtUnhandledDeveloperExceptionPermittingControlFlowInterruptions:caughtInterruptionException:whileExecutingBlock:]+0xb2 (XCTest:x86_64+0xa56d7)
    #22 0x101076f59 in __26-[XCTestCase performTest:]_block_invoke.362+0x55 (XCTest:x86_64+0x31f59)
    #23 0x1010fbb9e in +[XCTContext runInContextForTestCase:markAsReportingBase:block:]+0xdb (XCTest:x86_64+0xb6b9e)
    #24 0x1010767c6 in -[XCTestCase performTest:]+0x2b6 (XCTest:x86_64+0x317c6)
    #25 0x1010c86d9 in -[XCTest runTest]+0x38 (XCTest:x86_64+0x836d9)
    #26 0x101070034 in __27-[XCTestSuite performTest:]_block_invoke+0x148 (XCTest:x86_64+0x2b034)
    #27 0x10106f855 in __59-[XCTestSuite _performProtectedSectionForTest:testSection:]_block_invoke+0x17 (XCTest:x86_64+0x2a855)
    #28 0x1010fbb9e in +[XCTContext runInContextForTestCase:markAsReportingBase:block:]+0xdb (XCTest:x86_64+0xb6b9e)
    #29 0x1010fbaaf in +[XCTContext runInContextForTestCase:block:]+0x33 (XCTest:x86_64+0xb6aaf)
    #30 0x10106f80c in -[XCTestSuite _performProtectedSectionForTest:testSection:]+0x93 (XCTest:x86_64+0x2a80c)
    #31 0x10106fb10 in -[XCTestSuite performTest:]+0x121 (XCTest:x86_64+0x2ab10)
    #32 0x1010c86d9 in -[XCTest runTest]+0x38 (XCTest:x86_64+0x836d9)
    #33 0x101070034 in __27-[XCTestSuite performTest:]_block_invoke+0x148 (XCTest:x86_64+0x2b034)
    #34 0x10106f855 in __59-[XCTestSuite _performProtectedSectionForTest:testSection:]_block_invoke+0x17 (XCTest:x86_64+0x2a855)
    #35 0x1010fbb9e in +[XCTContext runInContextForTestCase:markAsReportingBase:block:]+0xdb (XCTest:x86_64+0xb6b9e)
    #36 0x1010fbaaf in +[XCTContext runInContextForTestCase:block:]+0x33 (XCTest:x86_64+0xb6aaf)
    #37 0x10106f80c in -[XCTestSuite _performProtectedSectionForTest:testSection:]+0x93 (XCTest:x86_64+0x2a80c)
    #38 0x10106fb10 in -[XCTestSuite performTest:]+0x121 (XCTest:x86_64+0x2ab10)
    #39 0x1010c86d9 in -[XCTest runTest]+0x38 (XCTest:x86_64+0x836d9)
    #40 0x101070034 in __27-[XCTestSuite performTest:]_block_invoke+0x148 (XCTest:x86_64+0x2b034)
    #41 0x10106f855 in __59-[XCTestSuite _performProtectedSectionForTest:testSection:]_block_invoke+0x17 (XCTest:x86_64+0x2a855)
    #42 0x1010fbb9e in +[XCTContext runInContextForTestCase:markAsReportingBase:block:]+0xdb (XCTest:x86_64+0xb6b9e)
    #43 0x1010fbaaf in +[XCTContext runInContextForTestCase:block:]+0x33 (XCTest:x86_64+0xb6aaf)
    #44 0x10106f80c in -[XCTestSuite _performProtectedSectionForTest:testSection:]+0x93 (XCTest:x86_64+0x2a80c)
    #45 0x10106fb10 in -[XCTestSuite performTest:]+0x121 (XCTest:x86_64+0x2ab10)
    #46 0x1010c86d9 in -[XCTest runTest]+0x38 (XCTest:x86_64+0x836d9)
    #47 0x1011188b4 in __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke_2+0x93 (XCTest:x86_64+0xd38b4)
    #48 0x1010fbb9e in +[XCTContext runInContextForTestCase:markAsReportingBase:block:]+0xdb (XCTest:x86_64+0xb6b9e)
    #49 0x1010fbaaf in +[XCTContext runInContextForTestCase:block:]+0x33 (XCTest:x86_64+0xb6aaf)
    #50 0x101118819 in __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke+0x6e (XCTest:x86_64+0xd3819)
    #51 0x10111899a in __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke.95+0x5f (XCTest:x86_64+0xd399a)
    #52 0x101096cb7 in -[XCTestObservationCenter _observeTestExecutionForBlock:]+0x144 (XCTest:x86_64+0x51cb7)
    #53 0x1011185df in -[XCTTestRunSession runTestsAndReturnError:]+0x266 (XCTest:x86_64+0xd35df)
    #54 0x101053a7d in -[XCTestDriver _runTests]+0x1d1 (XCTest:x86_64+0xea7d)
    #55 0x1010f7b81 in _XCTestMain+0x6b (XCTest:x86_64+0xb2b81)
    #56 0x100002f06 in main+0xd1 (xctest:x86_64+0x100002f06)
    #57 0x7fff686bccc8 in start+0x0 (libdyld.dylib:x86_64+0x1acc8)

0x610000050341 is located 1 bytes inside of 184-byte region [0x610000050340,0x6100000503f8)
freed by thread T0 here:
    #0 0x1001622c6 in wrap_free+0xa6 (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x492c6)
    #1 0x109c4b22e in cmark_strbuf_free+0x11e (CommonMarkTests:x86_64+0x4022e)
    #2 0x109c75aa2 in S_free_nodes+0x22 (CommonMarkTests:x86_64+0x6aaa2)
    #3 0x109c7562e in cmark_node_free+0x5e (CommonMarkTests:x86_64+0x6a62e)
    #4 0x109cdb4b8 in Node.deinit+0x1d8 (CommonMarkTests:x86_64+0xd04b8)
    #5 0x109cce275 in Paragraph.deinit+0x105 (CommonMarkTests:x86_64+0xc3275)
    #6 0x109cce3d5 in Paragraph.__deallocating_deinit+0x105 (CommonMarkTests:x86_64+0xc33d5)
    #7 0x7fff67fda1ef in _swift_release_dealloc+0xf (libswiftCore.dylib:x86_64+0x2f41ef)
    #8 0x7fff67fcff6a in swift_arrayDestroy+0x3a (libswiftCore.dylib:x86_64+0x2e9f6a)
    #9 0x7fff67d3e279 in _ContiguousArrayStorage.__deallocating_deinit+0x29 (libswiftCore.dylib:x86_64+0x58279)
    #10 0x7fff67fda1ef in _swift_release_dealloc+0xf (libswiftCore.dylib:x86_64+0x2f41ef)
    #11 0x109ce4cbe in static Node.extractRootInline(from:in:)+0xb2e (CommonMarkTests:x86_64+0xd9cbe)
    #12 0x109ce3025 in Node.__allocating_init(from:)+0x1e85 (CommonMarkTests:x86_64+0xd8025)
    #13 0x109ce5723 in protocol witness for Decodable.init(from:) in conformance Node+0x63 (CommonMarkTests:x86_64+0xda723)
    #14 0x7fff67fba376 in dispatch thunk of Decodable.init(from:)+0x6 (libswiftCore.dylib:x86_64+0x2d4376)
    #15 0x7fff681cee85 in __JSONDecoder.unbox_(_:as:)+0xe55 (libswiftFoundation.dylib:x86_64+0x8fe85)
    #16 0x7fff681c559c in _JSONUnkeyedDecodingContainer.decode<A>(_:)+0x33c (libswiftFoundation.dylib:x86_64+0x8659c)
    #17 0x7fff681c7ff8 in protocol witness for UnkeyedDecodingContainer.decode<A>(_:) in conformance _JSONUnkeyedDecodingContainer+0x8 (libswiftFoundation.dylib:x86_64+0x88ff8)
    #18 0x7fff67eddc0e in Array<A>.init(from:)+0x19e (libswiftCore.dylib:x86_64+0x1f7c0e)
    #19 0x7fff67ede3b2 in protocol witness for Decodable.init(from:) in conformance <A> [A]+0x12 (libswiftCore.dylib:x86_64+0x1f83b2)
    #20 0x7fff67edde0f in protocol witness for Decodable.init(from:) in conformance <A> [A]+0xf (libswiftCore.dylib:x86_64+0x1f7e0f)
    #21 0x7fff67fba376 in dispatch thunk of Decodable.init(from:)+0x6 (libswiftCore.dylib:x86_64+0x2d4376)
    #22 0x7fff681cee85 in __JSONDecoder.unbox_(_:as:)+0xe55 (libswiftFoundation.dylib:x86_64+0x8fe85)
    #23 0x7fff681b75b2 in JSONDecoder.decode<A>(_:from:)+0x2f2 (libswiftFoundation.dylib:x86_64+0x785b2)
    #24 0x7fff682901ae in dispatch thunk of JSONDecoder.decode<A>(_:from:)+0xe (libswiftFoundation.dylib:x86_64+0x1511ae)
    #25 0x109c1e1ca in DocumentCodingTests.testInlineElementCodingRoundTrip() DocumentCodingTests.swift:41
    #26 0x109c1f5a8 in @objc DocumentCodingTests.testInlineElementCodingRoundTrip() <compiler-generated>
    #27 0x7fff2e5e78ab in __invoking___+0x8b (CoreFoundation:x86_64h+0x658ab)
    #28 0x7fff2e5e7750 in -[NSInvocation invoke]+0x12e (CoreFoundation:x86_64h+0x65750)
    #29 0x101075d39 in __24-[XCTestCase invokeTest]_block_invoke_3+0x33 (XCTest:x86_64+0x30d39)

previously allocated by thread T0 here:
    #0 0x100162412 in wrap_realloc+0xa2 (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x49412)
    #1 0x109c4defc in xrealloc+0x1c (CommonMarkTests:x86_64+0x42efc)
    #2 0x109c4afc1 in cmark_strbuf_grow+0x2a1 (CommonMarkTests:x86_64+0x3ffc1)
    #3 0x109c4b9e3 in S_strbuf_grow_by+0x83 (CommonMarkTests:x86_64+0x409e3)
    #4 0x109c4ba20 in cmark_strbuf_put+0x30 (CommonMarkTests:x86_64+0x40a20)
    #5 0x109c4a56f in add_line+0x3df (CommonMarkTests:x86_64+0x3f56f)
    #6 0x109c42e6d in add_text_to_container+0x105d (CommonMarkTests:x86_64+0x37e6d)
    #7 0x109c3cf19 in S_process_line+0xb89 (CommonMarkTests:x86_64+0x31f19)
    #8 0x109c3bdeb in S_parser_feed+0x44b (CommonMarkTests:x86_64+0x30deb)
    #9 0x109c3c334 in cmark_parse_document+0x34 (CommonMarkTests:x86_64+0x31334)
    #10 0x109cd132d in Document.__allocating_init(_:options:)+0x88d (CommonMarkTests:x86_64+0xc632d)
    #11 0x109ce1af4 in Node.__allocating_init(from:)+0x954 (CommonMarkTests:x86_64+0xd6af4)
    #12 0x109ce5723 in protocol witness for Decodable.init(from:) in conformance Node+0x63 (CommonMarkTests:x86_64+0xda723)
    #13 0x7fff67fba376 in dispatch thunk of Decodable.init(from:)+0x6 (libswiftCore.dylib:x86_64+0x2d4376)
    #14 0x7fff681cee85 in __JSONDecoder.unbox_(_:as:)+0xe55 (libswiftFoundation.dylib:x86_64+0x8fe85)
    #15 0x7fff681c559c in _JSONUnkeyedDecodingContainer.decode<A>(_:)+0x33c (libswiftFoundation.dylib:x86_64+0x8659c)
    #16 0x7fff681c7ff8 in protocol witness for UnkeyedDecodingContainer.decode<A>(_:) in conformance _JSONUnkeyedDecodingContainer+0x8 (libswiftFoundation.dylib:x86_64+0x88ff8)
    #17 0x7fff67eddc0e in Array<A>.init(from:)+0x19e (libswiftCore.dylib:x86_64+0x1f7c0e)
    #18 0x7fff67ede3b2 in protocol witness for Decodable.init(from:) in conformance <A> [A]+0x12 (libswiftCore.dylib:x86_64+0x1f83b2)
    #19 0x7fff67edde0f in protocol witness for Decodable.init(from:) in conformance <A> [A]+0xf (libswiftCore.dylib:x86_64+0x1f7e0f)
    #20 0x7fff67fba376 in dispatch thunk of Decodable.init(from:)+0x6 (libswiftCore.dylib:x86_64+0x2d4376)
    #21 0x7fff681cee85 in __JSONDecoder.unbox_(_:as:)+0xe55 (libswiftFoundation.dylib:x86_64+0x8fe85)
    #22 0x7fff681b75b2 in JSONDecoder.decode<A>(_:from:)+0x2f2 (libswiftFoundation.dylib:x86_64+0x785b2)
    #23 0x7fff682901ae in dispatch thunk of JSONDecoder.decode<A>(_:from:)+0xe (libswiftFoundation.dylib:x86_64+0x1511ae)
    #24 0x109c1e1ca in DocumentCodingTests.testInlineElementCodingRoundTrip() DocumentCodingTests.swift:41
    #25 0x109c1f5a8 in @objc DocumentCodingTests.testInlineElementCodingRoundTrip() <compiler-generated>
    #26 0x7fff2e5e78ab in __invoking___+0x8b (CoreFoundation:x86_64h+0x658ab)
    #27 0x7fff2e5e7750 in -[NSInvocation invoke]+0x12e (CoreFoundation:x86_64h+0x65750)
    #28 0x101075d39 in __24-[XCTestCase invokeTest]_block_invoke_3+0x33 (XCTest:x86_64+0x30d39)
    #29 0x10113e214 in +[XCTSwiftErrorObservation observeErrorsInBlock:]+0x44 (XCTest:x86_64+0xf9214)

SUMMARY: AddressSanitizer: heap-use-after-free (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x4729f) in __asan_memcpy+0x1af
Shadow bytes around the buggy address:
  0x1c200000a010: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa
  0x1c200000a020: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
  0x1c200000a030: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa
  0x1c200000a040: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
  0x1c200000a050: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa
=>0x1c200000a060: fa fa fa fa fa fa fa fa[fd]fd fd fd fd fd fd fd
  0x1c200000a070: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa
  0x1c200000a080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c200000a090: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c200000a0a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c200000a0b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
2021-01-02 05:10:20.148801-0800 xctest[40289:2789453] =================================================================
2021-01-02 05:10:20.148861-0800 xctest[40289:2789453] ==40289==ERROR: AddressSanitizer: heap-use-after-free on address 0x610000050341 at pc 0x0001001602a0 bp 0x7ffeefbfbff0 sp 0x7ffeefbfb7b8
2021-01-02 05:10:20.148893-0800 xctest[40289:2789453] READ of size 37 at 0x610000050341 thread T0
2021-01-02 05:10:20.148927-0800 xctest[40289:2789453]     #0 0x10016029f in __asan_memcpy+0x1af (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x4729f)
2021-01-02 05:10:20.148961-0800 xctest[40289:2789453]     #1 0x109c768ae in cmark_chunk_to_cstr+0x29e (CommonMarkTests:x86_64+0x6b8ae)
2021-01-02 05:10:20.149024-0800 xctest[40289:2789453]     #2 0x109c765bb in cmark_node_get_literal+0xeb (CommonMarkTests:x86_64+0x6b5bb)
2021-01-02 05:10:20.149123-0800 xctest[40289:2789453]     #3 0x109c50dd5 in S_render_node+0x2065 (CommonMarkTests:x86_64+0x45dd5)
2021-01-02 05:10:20.149168-0800 xctest[40289:2789453]     #4 0x109c7d004 in cmark_render+0xb14 (CommonMarkTests:x86_64+0x72004)
2021-01-02 05:10:20.149216-0800 xctest[40289:2789453]     #5 0x109c4e324 in cmark_render_commonmark+0x44 (CommonMarkTests:x86_64+0x43324)
2021-01-02 05:10:20.149259-0800 xctest[40289:2789453]     #6 0x109ce0785 in Node.render(format:options:width:)+0x5e5 (CommonMarkTests:x86_64+0xd5785)
2021-01-02 05:10:20.149288-0800 xctest[40289:2789453]     #7 0x109ce5662 in Node.description.getter+0x182 (CommonMarkTests:x86_64+0xda662)
2021-01-02 05:10:20.149328-0800 xctest[40289:2789453]     #8 0x109c1e2fe in DocumentCodingTests.testInlineElementCodingRoundTrip() DocumentCodingTests.swift:43
2021-01-02 05:10:20.149400-0800 xctest[40289:2789453]     #9 0x109c1f5a8 in @objc DocumentCodingTests.testInlineElementCodingRoundTrip() <compiler-generated>
2021-01-02 05:10:20.149453-0800 xctest[40289:2789453]     #10 0x7fff2e5e78ab in __invoking___+0x8b (CoreFoundation:x86_64h+0x658ab)
2021-01-02 05:10:20.149487-0800 xctest[40289:2789453]     #11 0x7fff2e5e7750 in -[NSInvocation invoke]+0x12e (CoreFoundation:x86_64h+0x65750)
2021-01-02 05:10:20.149555-0800 xctest[40289:2789453]     #12 0x101075d39 in __24-[XCTestCase invokeTest]_block_invoke_3+0x33 (XCTest:x86_64+0x30d39)
2021-01-02 05:10:20.149611-0800 xctest[40289:2789453]     #13 0x10113e214 in +[XCTSwiftErrorObservation observeErrorsInBlock:]+0x44 (XCTest:x86_64+0xf9214)
2021-01-02 05:10:20.149716-0800 xctest[40289:2789453]     #14 0x101075c3b in __24-[XCTestCase invokeTest]_block_invoke_2+0x76 (XCTest:x86_64+0x30c3b)
2021-01-02 05:10:20.149781-0800 xctest[40289:2789453]     #15 0x101105599 in -[XCTMemoryChecker _assertInvalidObjectsDeallocatedAfterScope:]+0x40 (XCTest:x86_64+0xc0599)
2021-01-02 05:10:20.149830-0800 xctest[40289:2789453]     #16 0x1010808e9 in -[XCTestCase assertInvalidObjectsDeallocatedAfterScope:]+0x3c (XCTest:x86_64+0x3b8e9)
2021-01-02 05:10:20.149879-0800 xctest[40289:2789453]     #17 0x101075b81 in __24-[XCTestCase invokeTest]_block_invoke.231+0xc6 (XCTest:x86_64+0x30b81)
2021-01-02 05:10:20.149969-0800 xctest[40289:2789453]     #18 0x1010ea6d7 in -[XCTestCase(XCTIssueHandling) _caughtUnhandledDeveloperExceptionPermittingControlFlowInterruptions:caughtInterruptionException:whileExecutingBlock:]+0xb2 (XCTest:x86_64+0xa56d7)
2021-01-02 05:10:20.150062-0800 xctest[40289:2789453]     #19 0x101075644 in -[XCTestCase invokeTest]+0x40c (XCTest:x86_64+0x30644)
2021-01-02 05:10:20.150117-0800 xctest[40289:2789453]     #20 0x101077022 in __26-[XCTestCase performTest:]_block_invoke_2+0x2a (XCTest:x86_64+0x32022)
2021-01-02 05:10:20.150197-0800 xctest[40289:2789453]     #21 0x1010ea6d7 in -[XCTestCase(XCTIssueHandling) _caughtUnhandledDeveloperExceptionPermittingControlFlowInterruptions:caughtInterruptionException:whileExecutingBlock:]+0xb2 (XCTest:x86_64+0xa56d7)
2021-01-02 05:10:20.150277-0800 xctest[40289:2789453]     #22 0x101076f59 in __26-[XCTestCase performTest:]_block_invoke.362+0x55 (XCTest:x86_64+0x31f59)
2021-01-02 05:10:20.150364-0800 xctest[40289:2789453]     #23 0x1010fbb9e in +[XCTContext runInContextForTestCase:markAsReportingBase:block:]+0xdb (XCTest:x86_64+0xb6b9e)
2021-01-02 05:10:20.150404-0800 xctest[40289:2789453]     #24 0x1010767c6 in -[XCTestCase performTest:]+0x2b6 (XCTest:x86_64+0x317c6)
2021-01-02 05:10:20.150471-0800 xctest[40289:2789453]     #25 0x1010c86d9 in -[XCTest runTest]+0x38 (XCTest:x86_64+0x836d9)
2021-01-02 05:10:20.150534-0800 xctest[40289:2789453]     #26 0x101070034 in __27-[XCTestSuite performTest:]_block_invoke+0x148 (XCTest:x86_64+0x2b034)
2021-01-02 05:10:20.150594-0800 xctest[40289:2789453]     #27 0x10106f855 in __59-[XCTestSuite _performProtectedSectionForTest:testSection:]_block_invoke+0x17 (XCTest:x86_64+0x2a855)
2021-01-02 05:10:20.150678-0800 xctest[40289:2789453]     #28 0x1010fbb9e in +[XCTContext runInContextForTestCase:markAsReportingBase:block:]+0xdb (XCTest:x86_64+0xb6b9e)
2021-01-02 05:10:20.150722-0800 xctest[40289:2789453]     #29 0x1010fbaaf in +[XCTContext runInContextForTestCase:block:]+0x33 (XCTest:x86_64+0xb6aaf)
2021-01-02 05:10:20.150782-0800 xctest[40289:2789453]     #30 0x10106f80c in -[XCTestSuite _performProtectedSectionForTest:testSection:]+0x93 (XCTest:x86_64+0x2a80c)
2021-01-02 05:10:20.150826-0800 xctest[40289:2789453]     #31 0x10106fb10 in -[XCTestSuite performTest:]+0x121 (XCTest:x86_64+0x2ab10)
2021-01-02 05:10:20.150858-0800 xctest[40289:2789453]     #32 0x1010c86d9 in -[XCTest runTest]+0x38 (XCTest:x86_64+0x836d9)
2021-01-02 05:10:20.150921-0800 xctest[40289:2789453]     #33 0x101070034 in __27-[XCTestSuite performTest:]_block_invoke+0x148 (XCTest:x86_64+0x2b034)
2021-01-02 05:10:20.150983-0800 xctest[40289:2789453]     #34 0x10106f855 in __59-[XCTestSuite _performProtectedSectionForTest:testSection:]_block_invoke+0x17 (XCTest:x86_64+0x2a855)
2021-01-02 05:10:20.151021-0800 xctest[40289:2789453]     #35 0x1010fbb9e in +[XCTContext runInContextForTestCase:markAsReportingBase:block:]+0xdb (XCTest:x86_64+0xb6b9e)
2021-01-02 05:10:20.151111-0800 xctest[40289:2789453]     #36 0x1010fbaaf in +[XCTContext runInContextForTestCase:block:]+0x33 (XCTest:x86_64+0xb6aaf)
2021-01-02 05:10:20.151149-0800 xctest[40289:2789453]     #37 0x10106f80c in -[XCTestSuite _performProtectedSectionForTest:testSection:]+0x93 (XCTest:x86_64+0x2a80c)
2021-01-02 05:10:20.151180-0800 xctest[40289:2789453]     #38 0x10106fb10 in -[XCTestSuite performTest:]+0x121 (XCTest:x86_64+0x2ab10)
2021-01-02 05:10:20.151233-0800 xctest[40289:2789453]     #39 0x1010c86d9 in -[XCTest runTest]+0x38 (XCTest:x86_64+0x836d9)
2021-01-02 05:10:20.151277-0800 xctest[40289:2789453]     #40 0x101070034 in __27-[XCTestSuite performTest:]_block_invoke+0x148 (XCTest:x86_64+0x2b034)
2021-01-02 05:10:20.151324-0800 xctest[40289:2789453]     #41 0x10106f855 in __59-[XCTestSuite _performProtectedSectionForTest:testSection:]_block_invoke+0x17 (XCTest:x86_64+0x2a855)
2021-01-02 05:10:20.151373-0800 xctest[40289:2789453]     #42 0x1010fbb9e in +[XCTContext runInContextForTestCase:markAsReportingBase:block:]+0xdb (XCTest:x86_64+0xb6b9e)
2021-01-02 05:10:20.151408-0800 xctest[40289:2789453]     #43 0x1010fbaaf in +[XCTContext runInContextForTestCase:block:]+0x33 (XCTest:x86_64+0xb6aaf)
2021-01-02 05:10:20.151470-0800 xctest[40289:2789453]     #44 0x10106f80c in -[XCTestSuite _performProtectedSectionForTest:testSection:]+0x93 (XCTest:x86_64+0x2a80c)
2021-01-02 05:10:20.151535-0800 xctest[40289:2789453]     #45 0x10106fb10 in -[XCTestSuite performTest:]+0x121 (XCTest:x86_64+0x2ab10)
2021-01-02 05:10:20.151597-0800 xctest[40289:2789453]     #46 0x1010c86d9 in -[XCTest runTest]+0x38 (XCTest:x86_64+0x836d9)
2021-01-02 05:10:20.151636-0800 xctest[40289:2789453]     #47 0x1011188b4 in __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke_2+0x93 (XCTest:x86_64+0xd38b4)
2021-01-02 05:10:20.151693-0800 xctest[40289:2789453]     #48 0x1010fbb9e in +[XCTContext runInContextForTestCase:markAsReportingBase:block:]+0xdb (XCTest:x86_64+0xb6b9e)
2021-01-02 05:10:20.151740-0800 xctest[40289:2789453]     #49 0x1010fbaaf in +[XCTContext runInContextForTestCase:block:]+0x33 (XCTest:x86_64+0xb6aaf)
2021-01-02 05:10:20.151770-0800 xctest[40289:2789453]     #50 0x101118819 in __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke+0x6e (XCTest:x86_64+0xd3819)
2021-01-02 05:10:20.151817-0800 xctest[40289:2789453]     #51 0x10111899a in __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke.95+0x5f (XCTest:x86_64+0xd399a)
2021-01-02 05:10:20.151886-0800 xctest[40289:2789453]     #52 0x101096cb7 in -[XCTestObservationCenter _observeTestExecutionForBlock:]+0x144 (XCTest:x86_64+0x51cb7)
2021-01-02 05:10:20.151947-0800 xctest[40289:2789453]     #53 0x1011185df in -[XCTTestRunSession runTestsAndReturnError:]+0x266 (XCTest:x86_64+0xd35df)
2021-01-02 05:10:20.151997-0800 xctest[40289:2789453]     #54 0x101053a7d in -[XCTestDriver _runTests]+0x1d1 (XCTest:x86_64+0xea7d)
2021-01-02 05:10:20.152030-0800 xctest[40289:2789453]     #55 0x1010f7b81 in _XCTestMain+0x6b (XCTest:x86_64+0xb2b81)
2021-01-02 05:10:20.152108-0800 xctest[40289:2789453]     #56 0x100002f06 in main+0xd1 (xctest:x86_64+0x100002f06)
2021-01-02 05:10:20.152158-0800 xctest[40289:2789453]     #57 0x7fff686bccc8 in start+0x0 (libdyld.dylib:x86_64+0x1acc8)
2021-01-02 05:10:20.152190-0800 xctest[40289:2789453] 
2021-01-02 05:10:20.152244-0800 xctest[40289:2789453] 0x610000050341 is located 1 bytes inside of 184-byte region [0x610000050340,0x6100000503f8)
2021-01-02 05:10:20.152296-0800 xctest[40289:2789453] freed by thread T0 here:
2021-01-02 05:10:20.152336-0800 xctest[40289:2789453]     #0 0x1001622c6 in wrap_free+0xa6 (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x492c6)
2021-01-02 05:10:20.152367-0800 xctest[40289:2789453]     #1 0x109c4b22e in cmark_strbuf_free+0x11e (CommonMarkTests:x86_64+0x4022e)
2021-01-02 05:10:20.152441-0800 xctest[40289:2789453]     #2 0x109c75aa2 in S_free_nodes+0x22 (CommonMarkTests:x86_64+0x6aaa2)
2021-01-02 05:10:20.152487-0800 xctest[40289:2789453]     #3 0x109c7562e in cmark_node_free+0x5e (CommonMarkTests:x86_64+0x6a62e)
2021-01-02 05:10:20.152519-0800 xctest[40289:2789453]     #4 0x109cdb4b8 in Node.deinit+0x1d8 (CommonMarkTests:x86_64+0xd04b8)
2021-01-02 05:10:20.152583-0800 xctest[40289:2789453]     #5 0x109cce275 in Paragraph.deinit+0x105 (CommonMarkTests:x86_64+0xc3275)
2021-01-02 05:10:20.152631-0800 xctest[40289:2789453]     #6 0x109cce3d5 in Paragraph.__deallocating_deinit+0x105 (CommonMarkTests:x86_64+0xc33d5)
2021-01-02 05:10:20.152670-0800 xctest[40289:2789453]     #7 0x7fff67fda1ef in _swift_release_dealloc+0xf (libswiftCore.dylib:x86_64+0x2f41ef)
2021-01-02 05:10:20.152707-0800 xctest[40289:2789453]     #8 0x7fff67fcff6a in swift_arrayDestroy+0x3a (libswiftCore.dylib:x86_64+0x2e9f6a)
2021-01-02 05:10:20.152776-0800 xctest[40289:2789453]     #9 0x7fff67d3e279 in _ContiguousArrayStorage.__deallocating_deinit+0x29 (libswiftCore.dylib:x86_64+0x58279)
2021-01-02 05:10:20.152820-0800 xctest[40289:2789453]     #10 0x7fff67fda1ef in _swift_release_dealloc+0xf (libswiftCore.dylib:x86_64+0x2f41ef)
2021-01-02 05:10:20.152867-0800 xctest[40289:2789453]     #11 0x109ce4cbe in static Node.extractRootInline(from:in:)+0xb2e (CommonMarkTests:x86_64+0xd9cbe)
2021-01-02 05:10:20.152914-0800 xctest[40289:2789453]     #12 0x109ce3025 in Node.__allocating_init(from:)+0x1e85 (CommonMarkTests:x86_64+0xd8025)
2021-01-02 05:10:20.152980-0800 xctest[40289:2789453]     #13 0x109ce5723 in protocol witness for Decodable.init(from:) in conformance Node+0x63 (CommonMarkTests:x86_64+0xda723)
2021-01-02 05:10:20.153019-0800 xctest[40289:2789453]     #14 0x7fff67fba376 in dispatch thunk of Decodable.init(from:)+0x6 (libswiftCore.dylib:x86_64+0x2d4376)
2021-01-02 05:10:20.153056-0800 xctest[40289:2789453]     #15 0x7fff681cee85 in __JSONDecoder.unbox_(_:as:)+0xe55 (libswiftFoundation.dylib:x86_64+0x8fe85)
2021-01-02 05:10:20.153100-0800 xctest[40289:2789453]     #16 0x7fff681c559c in _JSONUnkeyedDecodingContainer.decode<A>(_:)+0x33c (libswiftFoundation.dylib:x86_64+0x8659c)
2021-01-02 05:10:20.153146-0800 xctest[40289:2789453]     #17 0x7fff681c7ff8 in protocol witness for UnkeyedDecodingContainer.decode<A>(_:) in conformance _JSONUnkeyedDecodingContainer+0x8 (libswiftFoundation.dylib:x86_64+0x88ff8)
2021-01-02 05:10:20.153177-0800 xctest[40289:2789453]     #18 0x7fff67eddc0e in Array<A>.init(from:)+0x19e (libswiftCore.dylib:x86_64+0x1f7c0e)
2021-01-02 05:10:20.153236-0800 xctest[40289:2789453]     #19 0x7fff67ede3b2 in protocol witness for Decodable.init(from:) in conformance <A> [A]+0x12 (libswiftCore.dylib:x86_64+0x1f83b2)
2021-01-02 05:10:20.153296-0800 xctest[40289:2789453]     #20 0x7fff67edde0f in protocol witness for Decodable.init(from:) in conformance <A> [A]+0xf (libswiftCore.dylib:x86_64+0x1f7e0f)
2021-01-02 05:10:20.153337-0800 xctest[40289:2789453]     #21 0x7fff67fba376 in dispatch thunk of Decodable.init(from:)+0x6 (libswiftCore.dylib:x86_64+0x2d4376)
2021-01-02 05:10:20.153381-0800 xctest[40289:2789453]     #22 0x7fff681cee85 in __JSONDecoder.unbox_(_:as:)+0xe55 (libswiftFoundation.dylib:x86_64+0x8fe85)
2021-01-02 05:10:20.153429-0800 xctest[40289:2789453]     #23 0x7fff681b75b2 in JSONDecoder.decode<A>(_:from:)+0x2f2 (libswiftFoundation.dylib:x86_64+0x785b2)
2021-01-02 05:10:20.153474-0800 xctest[40289:2789453]     #24 0x7fff682901ae in dispatch thunk of JSONDecoder.decode<A>(_:from:)+0xe (libswiftFoundation.dylib:x86_64+0x1511ae)
2021-01-02 05:10:20.153505-0800 xctest[40289:2789453]     #25 0x109c1e1ca in DocumentCodingTests.testInlineElementCodingRoundTrip() DocumentCodingTests.swift:41
2021-01-02 05:10:20.153536-0800 xctest[40289:2789453]     #26 0x109c1f5a8 in @objc DocumentCodingTests.testInlineElementCodingRoundTrip() <compiler-generated>
2021-01-02 05:10:20.153593-0800 xctest[40289:2789453]     #27 0x7fff2e5e78ab in __invoking___+0x8b (CoreFoundation:x86_64h+0x658ab)
2021-01-02 05:10:20.153641-0800 xctest[40289:2789453]     #28 0x7fff2e5e7750 in -[NSInvocation invoke]+0x12e (CoreFoundation:x86_64h+0x65750)
2021-01-02 05:10:20.153675-0800 xctest[40289:2789453]     #29 0x101075d39 in __24-[XCTestCase invokeTest]_block_invoke_3+0x33 (XCTest:x86_64+0x30d39)
2021-01-02 05:10:20.153721-0800 xctest[40289:2789453] 
2021-01-02 05:10:20.153795-0800 xctest[40289:2789453] previously allocated by thread T0 here:
2021-01-02 05:10:20.153833-0800 xctest[40289:2789453]     #0 0x100162412 in wrap_realloc+0xa2 (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x49412)
2021-01-02 05:10:20.153893-0800 xctest[40289:2789453]     #1 0x109c4defc in xrealloc+0x1c (CommonMarkTests:x86_64+0x42efc)
2021-01-02 05:10:20.153956-0800 xctest[40289:2789453]     #2 0x109c4afc1 in cmark_strbuf_grow+0x2a1 (CommonMarkTests:x86_64+0x3ffc1)
2021-01-02 05:10:20.154000-0800 xctest[40289:2789453]     #3 0x109c4b9e3 in S_strbuf_grow_by+0x83 (CommonMarkTests:x86_64+0x409e3)
2021-01-02 05:10:20.154068-0800 xctest[40289:2789453]     #4 0x109c4ba20 in cmark_strbuf_put+0x30 (CommonMarkTests:x86_64+0x40a20)
2021-01-02 05:10:20.154132-0800 xctest[40289:2789453]     #5 0x109c4a56f in add_line+0x3df (CommonMarkTests:x86_64+0x3f56f)
2021-01-02 05:10:20.154166-0800 xctest[40289:2789453]     #6 0x109c42e6d in add_text_to_container+0x105d (CommonMarkTests:x86_64+0x37e6d)
2021-01-02 05:10:20.154230-0800 xctest[40289:2789453]     #7 0x109c3cf19 in S_process_line+0xb89 (CommonMarkTests:x86_64+0x31f19)
2021-01-02 05:10:20.154293-0800 xctest[40289:2789453]     #8 0x109c3bdeb in S_parser_feed+0x44b (CommonMarkTests:x86_64+0x30deb)
2021-01-02 05:10:20.154355-0800 xctest[40289:2789453]     #9 0x109c3c334 in cmark_parse_document+0x34 (CommonMarkTests:x86_64+0x31334)
2021-01-02 05:10:20.154437-0800 xctest[40289:2789453]     #10 0x109cd132d in Document.__allocating_init(_:options:)+0x88d (CommonMarkTests:x86_64+0xc632d)
2021-01-02 05:10:20.154492-0800 xctest[40289:2789453]     #11 0x109ce1af4 in Node.__allocating_init(from:)+0x954 (CommonMarkTests:x86_64+0xd6af4)
2021-01-02 05:10:20.154550-0800 xctest[40289:2789453]     #12 0x109ce5723 in protocol witness for Decodable.init(from:) in conformance Node+0x63 (CommonMarkTests:x86_64+0xda723)
2021-01-02 05:10:20.154612-0800 xctest[40289:2789453]     #13 0x7fff67fba376 in dispatch thunk of Decodable.init(from:)+0x6 (libswiftCore.dylib:x86_64+0x2d4376)
2021-01-02 05:10:20.154641-0800 xctest[40289:2789453]     #14 0x7fff681cee85 in __JSONDecoder.unbox_(_:as:)+0xe55 (libswiftFoundation.dylib:x86_64+0x8fe85)
2021-01-02 05:10:20.154675-0800 xctest[40289:2789453]     #15 0x7fff681c559c in _JSONUnkeyedDecodingContainer.decode<A>(_:)+0x33c (libswiftFoundation.dylib:x86_64+0x8659c)
2021-01-02 05:10:20.154729-0800 xctest[40289:2789453]     #16 0x7fff681c7ff8 in protocol witness for UnkeyedDecodingContainer.decode<A>(_:) in conformance _JSONUnkeyedDecodingContainer+0x8 (libswiftFoundation.dylib:x86_64+0x88ff8)
2021-01-02 05:10:20.154763-0800 xctest[40289:2789453]     #17 0x7fff67eddc0e in Array<A>.init(from:)+0x19e (libswiftCore.dylib:x86_64+0x1f7c0e)
2021-01-02 05:10:20.154792-0800 xctest[40289:2789453]     #18 0x7fff67ede3b2 in protocol witness for Decodable.init(from:) in conformance <A> [A]+0x12 (libswiftCore.dylib:x86_64+0x1f83b2)
2021-01-02 05:10:20.154832-0800 xctest[40289:2789453]     #19 0x7fff67edde0f in protocol witness for Decodable.init(from:) in conformance <A> [A]+0xf (libswiftCore.dylib:x86_64+0x1f7e0f)
2021-01-02 05:10:20.154863-0800 xctest[40289:2789453]     #20 0x7fff67fba376 in dispatch thunk of Decodable.init(from:)+0x6 (libswiftCore.dylib:x86_64+0x2d4376)
2021-01-02 05:10:20.154907-0800 xctest[40289:2789453]     #21 0x7fff681cee85 in __JSONDecoder.unbox_(_:as:)+0xe55 (libswiftFoundation.dylib:x86_64+0x8fe85)
2021-01-02 05:10:20.154939-0800 xctest[40289:2789453]     #22 0x7fff681b75b2 in JSONDecoder.decode<A>(_:from:)+0x2f2 (libswiftFoundation.dylib:x86_64+0x785b2)
2021-01-02 05:10:20.154967-0800 xctest[40289:2789453]     #23 0x7fff682901ae in dispatch thunk of JSONDecoder.decode<A>(_:from:)+0xe (libswiftFoundation.dylib:x86_64+0x1511ae)
2021-01-02 05:10:20.154997-0800 xctest[40289:2789453]     #24 0x109c1e1ca in DocumentCodingTests.testInlineElementCodingRoundTrip() DocumentCodingTests.swift:41
2021-01-02 05:10:20.155061-0800 xctest[40289:2789453]     #25 0x109c1f5a8 in @objc DocumentCodingTests.testInlineElementCodingRoundTrip() <compiler-generated>
2021-01-02 05:10:20.155114-0800 xctest[40289:2789453]     #26 0x7fff2e5e78ab in __invoking___+0x8b (CoreFoundation:x86_64h+0x658ab)
2021-01-02 05:10:20.155180-0800 xctest[40289:2789453]     #27 0x7fff2e5e7750 in -[NSInvocation invoke]+0x12e (CoreFoundation:x86_64h+0x65750)
2021-01-02 05:10:20.155239-0800 xctest[40289:2789453]     #28 0x101075d39 in __24-[XCTestCase invokeTest]_block_invoke_3+0x33 (XCTest:x86_64+0x30d39)
2021-01-02 05:10:20.155291-0800 xctest[40289:2789453]     #29 0x10113e214 in +[XCTSwiftErrorObservation observeErrorsInBlock:]+0x44 (XCTest:x86_64+0xf9214)
2021-01-02 05:10:20.155361-0800 xctest[40289:2789453] 
2021-01-02 05:10:20.155414-0800 xctest[40289:2789453] SUMMARY: AddressSanitizer: heap-use-after-free (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x4729f) in __asan_memcpy+0x1af
2021-01-02 05:10:20.155501-0800 xctest[40289:2789453] Shadow bytes around the buggy address:
2021-01-02 05:10:20.155559-0800 xctest[40289:2789453]   0x1c200000a010: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa
2021-01-02 05:10:20.155616-0800 xctest[40289:2789453]   0x1c200000a020: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
2021-01-02 05:10:20.155666-0800 xctest[40289:2789453]   0x1c200000a030: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa
2021-01-02 05:10:20.155719-0800 xctest[40289:2789453]   0x1c200000a040: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
2021-01-02 05:10:20.155781-0800 xctest[40289:2789453]   0x1c200000a050: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa
2021-01-02 05:10:20.155834-0800 xctest[40289:2789453] =>0x1c200000a060: fa fa fa fa fa fa fa fa[fd]fd fd fd fd fd fd fd
2021-01-02 05:10:20.155890-0800 xctest[40289:2789453]   0x1c200000a070: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa
2021-01-02 05:10:20.155934-0800 xctest[40289:2789453]   0x1c200000a080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
2021-01-02 05:10:20.156003-0800 xctest[40289:2789453]   0x1c200000a090: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
2021-01-02 05:10:20.156076-0800 xctest[40289:2789453]   0x1c200000a0a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
2021-01-02 05:10:20.156143-0800 xctest[40289:2789453]   0x1c200000a0b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
2021-01-02 05:10:20.156198-0800 xctest[40289:2789453] Shadow byte legend (one shadow byte represents 8 application bytes):
2021-01-02 05:10:20.156293-0800 xctest[40289:2789453]   Addressable:           00
2021-01-02 05:10:20.156327-0800 xctest[40289:2789453]   Partially addressable: 01 02 03 04 05 06 07
2021-01-02 05:10:20.156396-0800 xctest[40289:2789453]   Heap left redzone:       fa
2021-01-02 05:10:20.156440-0800 xctest[40289:2789453]   Freed heap region:       fd
2021-01-02 05:10:20.156474-0800 xctest[40289:2789453]   Stack left redzone:      f1
2021-01-02 05:10:20.156505-0800 xctest[40289:2789453]   Stack mid redzone:       f2
2021-01-02 05:10:20.156554-0800 xctest[40289:2789453]   Stack right redzone:     f3
2021-01-02 05:10:20.156606-0800 xctest[40289:2789453]   Stack after return:      f5
2021-01-02 05:10:20.156651-0800 xctest[40289:2789453]   Stack use after scope:   f8
2021-01-02 05:10:20.156734-0800 xctest[40289:2789453]   Global redzone:          f9
2021-01-02 05:10:20.156776-0800 xctest[40289:2789453]   Global init order:       f6
2021-01-02 05:10:20.156828-0800 xctest[40289:2789453]   Poisoned by user:        f7
2021-01-02 05:10:20.156897-0800 xctest[40289:2789453]   Container overflow:      fc
2021-01-02 05:10:20.156941-0800 xctest[40289:2789453]   Array cookie:            ac
2021-01-02 05:10:20.156995-0800 xctest[40289:2789453]   Intra object redzone:    bb
2021-01-02 05:10:20.157047-0800 xctest[40289:2789453]   ASan internal:           fe
2021-01-02 05:10:20.157110-0800 xctest[40289:2789453]   Left alloca redzone:     ca
2021-01-02 05:10:20.157181-0800 xctest[40289:2789453]   Right alloca redzone:    cb
2021-01-02 05:10:20.157250-0800 xctest[40289:2789453]   Shadow gap:              cc
==40289==ABORTING
AddressSanitizer report breakpoint hit. Use 'thread info -s' to get extended information about the report.
(lldb) 
mattt commented 3 years ago

@regexident I spent a good hour or two trying to find anything wrong with the code you wrote. After exhausting all of my leads, I considered whether the memory bug was in cmark itself (as ASAN seemed to indicate). Sure enough, updating to 0.29.0 (#24) resolves the failing test case.

regexident commented 3 years ago

Hah! I spent some time in the cmark code-base looking, too. But mostly looking for things that might point to CommonMark making wrong use of their API, but couldn't find anything.

Thanks for the helping hand @mattt!

regexident commented 3 years ago

LGTM! ๐Ÿ’ช

mattt commented 3 years ago

Thanks for your patience and all of your help with this, @regexident. Merging this in now!

regexident commented 3 years ago

Awesome! Glad I could help. ๐Ÿ™‚