Bug 23395 – Regex leaks memory when used in multithreaded environment

Status
NEW
Severity
minor
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2022-10-07T16:07:24Z
Last change time
2024-12-01T16:40:32Z
Assigned to
No Owner
Creator
anon
Moved to GitHub: phobos#9847 →

Comments

Comment #0 by qigezx+dc40d6nao940k — 2022-10-07T16:07:24Z
Each thread where regular expressions are used leaks memory exactly once, I think that only the first created regex leaks. This is true for (CTR) compile time and runtime regex. CTR leak much more memory. The leak grows or shrinks depending on the size of the regex. Compile the following example with "ldc2 -fsan=address -g" to see for yourself. It also works with gdc and dmd, but at least for dmd you need to use valgrind instead, which is more ambigious and less informative in it's reporting for this bug. ``` import std; void threadFun(){ auto rgx = regex(r"(?P<num>\d)"); auto res = matchFirst(words, rgx); res["num"].writeln; } void main(){ foreach(i; 0..10){ task!(threadFun).executeInNewThread(); } } ```
Comment #1 by qigezx+dc40d6nao940k — 2022-11-10T20:27:05Z
This is especially important when using unit_threaded as this is also when you want to enable fsan
Comment #2 by robert.schadek — 2024-12-01T16:40:32Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9847 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB