scinfu / SwiftSoup

SwiftSoup: Pure Swift HTML Parser, with best of DOM, CSS, and jquery (Supports Linux, iOS, Mac, tvOS, watchOS)
https://scinfu.github.io/SwiftSoup/
MIT License
4.52k stars 345 forks source link

Memory Leak #287

Open lissine0 opened 3 weeks ago

lissine0 commented 3 weeks ago

We are using SwiftSoup to parse the html in MLOgHtmlParser.swift in order to create an url preview.

Sometimes parsing will swallow up all available ram+swap until the OS kills the app.

URL triggering this (needed 42 minutes on a x86 macOS computer to crash with an out of memory error): https://bugs.documentfoundation.org/buglist.cgi?bug_id=34340,36958,63598,84583,85435,100758,106108,122784,129808,132064,132274,133066,134629,135424,137298,141577,142120,142244,144050,144113,146231,146998,147399,148857,148865,151754,152297,152298,153188,153507,153772,155612,156047,156555,157324,157334,157662,158092,159362,159501,159548,159618,159818,159819,159832,159853,159856,159867,159869,159902,1

tmolitor-stud-tu commented 6 days ago

message at /usr/lib/swift/libswiftCore.dylib: Could not allocate memory.

Example stacktrace:

Thread 4 Crashed:
0   libswiftCore.dylib              0x00000001a618e274 0x1a5d30000 + 4579956 (<redacted> + 16)
1   libswiftCore.dylib              0x00000001a60d7228 0x1a5d30000 + 3830312 (<redacted> + 108)
2   libswiftCore.dylib              0x00000001a60d7684 0x1a5d30000 + 3831428 (<redacted> + 1112)
3   Monal                           0x0000000102c2d940 0x102aa0000 + 1628480 ($ss22_ContiguousArrayBufferV19_uninitializedCount15minimumCapacityAByxGSi_SitcfCSS_Tgm5Tm + 52)
4   Monal                           0x0000000102bda0a4 0x102aa0000 + 1286308 (specialized _ArrayBuffer._consumeAndCreateNew(bufferIsUnique:minimumCapacity:growForAppend:) + 92)
5   Monal                           0x0000000102c2c9c0 0x102aa0000 + 1624512 (StringBuilder.append(_:) + 196)
6   Monal                           0x0000000102c381dc 0x102aa0000 + 1671644 (Tokeniser.emit(_:) + 136)
7   Monal                           0x0000000102c3b074 0x102aa0000 + 1683572 (TokeniserState.read(_:_:) + 5004)
8   Monal                           0x0000000102c23904 0x102aa0000 + 1587460 (specialized static Parser.parse(_:_:) + 356)
9   Monal                           0x0000000102c23228 0x102aa0000 + 1585704 (static Parser.parse(_:_:) + 12)
10  Monal                           0x0000000102ba0e34 0x102aa0000 + 1052212 (MLOgHtmlParser.init(html:andBaseUrl:) + 244)
11  Monal                           0x0000000102ba1b3c 0x102aa0000 + 1055548 (@objc MLOgHtmlParser.init(html:andBaseUrl:) + 204)
12  Monal                           0x0000000102d0cabc 0x102aa0000 + 2542268 (__77-[chatViewController downloadPreviewWithRow:usingByterange:andResultHandler:]_block_invoke + 420)
13  CFNetwork                       0x00000001a85a9c70 0x1a853f000 + 437360 (CFHTTPCookieCreateWithResponseHeaderFields + 62444)
14  CFNetwork                       0x00000001a85a9a44 0x1a853f000 + 436804 (CFHTTPCookieCreateWithResponseHeaderFields + 61888)
15  libdispatch.dylib               0x00000001af33113c 0x1af32f000 + 8508 (<redacted> + 32)
16  libdispatch.dylib               0x00000001af332dd4 0x1af32f000 + 15828 (<redacted> + 20)
17  libdispatch.dylib               0x00000001af33a400 0x1af32f000 + 46080 (<redacted> + 748)
18  libdispatch.dylib               0x00000001af33af64 0x1af32f000 + 48996 (<redacted> + 432)
19  libdispatch.dylib               0x00000001af345cb4 0x1af32f000 + 93364 (<redacted> + 288)
20  libdispatch.dylib               0x00000001af345528 0x1af32f000 + 91432 (<redacted> + 404)
21  libsystem_pthread.dylib         0x0000000203edc934 0x203ed8000 + 18740 (_pthread_wqthread + 288)