Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Free stuff properly in zsh/pcre module
- X-seq: zsh-workers 42243
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: Free stuff properly in zsh/pcre module
- Date: Sun, 7 Jan 2018 15:09:39 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=TXtIqo/R8zt/qEk4dWcaICTbhRwYStpQQWRmwmQdGus=; b=IKAC4cTFq38w3ffTlJj2SNnqW21DolSOu5Mj6EB4/OBg7GveCLrKorZpwCq9CVFpfm e1wyjNgIKeM1/wSH8L1E1dV6ZNy8rhsPMZ2AhN5XwWFqDyPzE0gOoZzrRBqX7s5fI52t 0KMFalSo+6rIzCudFjugbGuGyUvELbERyIoVHPyIHWn+vQNfun4AjkJ45WgbP90oragN gYHh/AoZ95aevuBvS3aQrbG84U5eZj4tEuq/mBf/fiDGHZ/Ul23FWNHPK53VX1r+sQHz A1SqF9BncyuHFGvBSa3mmSgItHsZWCmsKbrsWLJ/tsu/PxBWncd7au7CnLlt48HHTq3I YQVQ==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
Fix a few memleaks of the hints structure, also make sure to free all
the allocated stuff when the module is unloaded.
---
If you run
% zmodload zsh/pcre; pcre_compile hey; repeat 1000000; do pcre_study; done
then zsh mem usage goes up by about 100MB each time.
Src/Modules/pcre.c | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/Src/Modules/pcre.c b/Src/Modules/pcre.c
index 659fd22d59..15ee34bc8f 100644
--- a/Src/Modules/pcre.c
+++ b/Src/Modules/pcre.c
@@ -88,10 +88,19 @@ bin_pcre_compile(char *nam, char **args, Options ops, UNUSED(int func))
if (zpcre_utf8_enabled())
pcre_opts |= PCRE_UTF8;
- pcre_hints = NULL; /* Is this necessary? */
+#ifdef HAVE_PCRE_STUDY
+ if (pcre_hints)
+#ifdef PCRE_CONFIG_JIT
+ pcre_free_study(pcre_hints);
+#else
+ pcre_free(pcre_hints);
+#endif
+ pcre_hints = NULL;
+#endif
if (pcre_pattern)
pcre_free(pcre_pattern);
+ pcre_pattern = NULL;
target = ztrdup(*args);
unmetafy(target, &target_len);
@@ -128,6 +137,14 @@ bin_pcre_study(char *nam, UNUSED(char **args), UNUSED(Options ops), UNUSED(int f
return 1;
}
+ if (pcre_hints)
+#ifdef PCRE_CONFIG_JIT
+ pcre_free_study(pcre_hints);
+#else
+ pcre_free(pcre_hints);
+#endif
+ pcre_hints = NULL;
+
pcre_hints = pcre_study(pcre_pattern, 0, &pcre_error);
if (pcre_error != NULL)
{
@@ -528,5 +545,21 @@ cleanup_(Module m)
int
finish_(UNUSED(Module m))
{
+#if defined(HAVE_PCRE_COMPILE) && defined(HAVE_PCRE_EXEC)
+#ifdef HAVE_PCRE_STUDY
+ if (pcre_hints)
+#ifdef PCRE_CONFIG_JIT
+ pcre_free_study(pcre_hints);
+#else
+ pcre_free(pcre_hints);
+#endif
+ pcre_hints = NULL;
+#endif
+
+ if (pcre_pattern)
+ pcre_free(pcre_pattern);
+ pcre_pattern = NULL;
+#endif
+
return 0;
}
--
2.15.1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author