[sr-dev] git:4.4:7a3f8995: regex: free unused tmp pkg memory for reloaded patterns

Daniel-Constantin Mierla miconda at gmail.com
Thu Nov 2 08:53:05 CET 2017


Module: kamailio
Branch: 4.4
Commit: 7a3f89954ef1d2daf49fb9a7b7e080c2edecc174
URL: https://github.com/kamailio/kamailio/commit/7a3f89954ef1d2daf49fb9a7b7e080c2edecc174

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-11-02T08:52:16+01:00

regex: free unused tmp pkg memory for reloaded patterns

- use memset instead of for loop to init allocated memory to 0
- partial backport of 5f8dc56f3cb47d1e804fbc3d7f5321ce979d61d9

---

Modified: modules/regex/regex_mod.c

---

Diff:  https://github.com/kamailio/kamailio/commit/7a3f89954ef1d2daf49fb9a7b7e080c2edecc174.diff
Patch: https://github.com/kamailio/kamailio/commit/7a3f89954ef1d2daf49fb9a7b7e080c2edecc174.patch

---

diff --git a/modules/regex/regex_mod.c b/modules/regex/regex_mod.c
index 71acfc955b..645ef29598 100644
--- a/modules/regex/regex_mod.c
+++ b/modules/regex/regex_mod.c
@@ -431,9 +431,7 @@ static int load_pcres(int action)
 		LM_ERR("no more memory for pcres\n");
 		goto err;
 	}
-	for (i=0; i<num_pcres_tmp; i++) {
-		pcres[i] = NULL;
-	}
+	memset(pcres, 0, sizeof(pcre *) * num_pcres_tmp);
 	for (i=0; i<num_pcres_tmp; i++) {
 		pcre_rc = pcre_fullinfo(pcres_tmp[i], NULL, PCRE_INFO_SIZE, &pcre_size);
 		if ((pcres[i] = shm_malloc(pcre_size)) == 0) {
@@ -450,6 +448,10 @@ static int load_pcres(int action)
 		pkg_free(pcres_tmp[i]);
 	}
 	pkg_free(pcres_tmp);
+	/* Free allocated slots for unused patterns */
+	for (i = num_pcres_tmp; i < max_groups; i++) {
+		pkg_free(patterns[i]);
+	}
 	pkg_free(patterns);
 	lock_release(reload_lock);
 	




More information about the sr-dev mailing list