From 9d4190a5cc426dfbb515526d3c0b22c418e07d16 Mon Sep 17 00:00:00 2001 From: Miran Date: Thu, 16 May 2019 21:06:31 +0200 Subject: [PATCH] fixes #11139 (re.nim memory leak) (#11265) Use the same PCRE function for freeing up the memory as nre.nim does. --- lib/impure/nre.nim | 1 - lib/impure/re.nim | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/impure/nre.nim b/lib/impure/nre.nim index 7014af42ab..8848b8d5b7 100644 --- a/lib/impure/nre.nim +++ b/lib/impure/nre.nim @@ -440,7 +440,6 @@ proc extractOptions(pattern: string): tuple[pattern: string, flags: int, study: proc destroyRegex(pattern: Regex) = pcre.free_substring(cast[cstring](pattern.pcreObj)) - pattern.pcreObj = nil if pattern.pcreExtra != nil: pcre.free_study(pattern.pcreExtra) diff --git a/lib/impure/re.nim b/lib/impure/re.nim index 4f32cd5fb9..34ccd8f1a9 100644 --- a/lib/impure/re.nim +++ b/lib/impure/re.nim @@ -65,7 +65,7 @@ proc finalizeRegEx(x: Regex) = # Fortunately the implementation is unlikely to change. pcre.free_substring(cast[cstring](x.h)) if not isNil(x.e): - pcre.free_substring(cast[cstring](x.e)) + pcre.free_study(x.e) proc re*(s: string, flags = {reStudy}): Regex = ## Constructor of regular expressions.