changeset 713:3ea040bb0dca

Fix a memory leak in regex tests.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 27 Apr 2020 01:35:39 +0300
parents 838189b856f3
children ec6a3790a91b
files tests.c
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tests.c	Mon Apr 27 01:31:53 2020 +0300
+++ b/tests.c	Mon Apr 27 01:35:39 2020 +0300
@@ -646,6 +646,7 @@
 
 void test_regex_list1(const test_regex_def1 *list, const th_char_t *pattern)
 {
+    th_regex_match_t *matches = NULL;
     th_regex_t *expr = NULL;
     int res;
 
@@ -665,7 +666,6 @@
 
     for (const test_regex_def1 *def = list; def->str != NULL; def++)
     {
-        th_regex_match_t *matches = NULL;
         size_t nmatches;
         BOOL matchOK;
 
@@ -675,6 +675,7 @@
         {
             THERR("Regex match returned error: %s\n",
                 th_error_str(res));
+
             goto out;
         }
 
@@ -705,9 +706,11 @@
         test_regex_list_matches(def->str, matches, def->expected, FALSE);
 
         th_regex_free_matches(matches);
+        matches = NULL;
     }
 
 out:
+    th_regex_free_matches(matches);
     th_regex_free(expr);
 }