summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMiran <narimiran@disroot.org>2019-05-16 21:06:31 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-05-16 21:06:31 +0200
commit9d4190a5cc426dfbb515526d3c0b22c418e07d16 (patch)
tree56b46fc37f3b096f174ff2530970a3f0c3a042a3
parent8f198db2cae0af718a3563bba53f4caf9bc46748 (diff)
downloadNim-9d4190a5cc426dfbb515526d3c0b22c418e07d16.tar.gz
fixes #11139 (re.nim memory leak) (#11265)
Use the same PCRE function for freeing up the memory as nre.nim does.
-rw-r--r--lib/impure/nre.nim1
-rw-r--r--lib/impure/re.nim2
2 files changed, 1 insertions, 2 deletions
diff --git a/lib/impure/nre.nim b/lib/impure/nre.nim
index 7014af42a..8848b8d5b 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 4f32cd5fb..34ccd8f1a 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.