Mercurial > hg > th-libs
comparison tests.c @ 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 | c1c37f6ca133 |
children | 388d72f4189d |
comparison
equal
deleted
inserted
replaced
712:838189b856f3 | 713:3ea040bb0dca |
---|---|
644 } | 644 } |
645 | 645 |
646 | 646 |
647 void test_regex_list1(const test_regex_def1 *list, const th_char_t *pattern) | 647 void test_regex_list1(const test_regex_def1 *list, const th_char_t *pattern) |
648 { | 648 { |
649 th_regex_match_t *matches = NULL; | |
649 th_regex_t *expr = NULL; | 650 th_regex_t *expr = NULL; |
650 int res; | 651 int res; |
651 | 652 |
652 if ((res = th_regex_compile(&expr, pattern)) != THERR_OK) | 653 if ((res = th_regex_compile(&expr, pattern)) != THERR_OK) |
653 { | 654 { |
663 if (th_verbosity >= 2) | 664 if (th_verbosity >= 2) |
664 th_regex_dump(&testio, 1, expr); | 665 th_regex_dump(&testio, 1, expr); |
665 | 666 |
666 for (const test_regex_def1 *def = list; def->str != NULL; def++) | 667 for (const test_regex_def1 *def = list; def->str != NULL; def++) |
667 { | 668 { |
668 th_regex_match_t *matches = NULL; | |
669 size_t nmatches; | 669 size_t nmatches; |
670 BOOL matchOK; | 670 BOOL matchOK; |
671 | 671 |
672 tprint(3, "\n----------------------------------------\n"); | 672 tprint(3, "\n----------------------------------------\n"); |
673 if ((res = th_regex_match(expr, def->str, | 673 if ((res = th_regex_match(expr, def->str, |
674 &nmatches, &matches, -1, def->flags)) != THERR_OK) | 674 &nmatches, &matches, -1, def->flags)) != THERR_OK) |
675 { | 675 { |
676 THERR("Regex match returned error: %s\n", | 676 THERR("Regex match returned error: %s\n", |
677 th_error_str(res)); | 677 th_error_str(res)); |
678 | |
678 goto out; | 679 goto out; |
679 } | 680 } |
680 | 681 |
681 matchOK = test_regex_list_matches(def->str, matches, def->expected, TRUE); | 682 matchOK = test_regex_list_matches(def->str, matches, def->expected, TRUE); |
682 if (th_verbosity < 1 && !matchOK) | 683 if (th_verbosity < 1 && !matchOK) |
703 #endif | 704 #endif |
704 | 705 |
705 test_regex_list_matches(def->str, matches, def->expected, FALSE); | 706 test_regex_list_matches(def->str, matches, def->expected, FALSE); |
706 | 707 |
707 th_regex_free_matches(matches); | 708 th_regex_free_matches(matches); |
709 matches = NULL; | |
708 } | 710 } |
709 | 711 |
710 out: | 712 out: |
713 th_regex_free_matches(matches); | |
711 th_regex_free(expr); | 714 th_regex_free(expr); |
712 } | 715 } |
713 | 716 |
714 | 717 |
715 void test_regex_list2(const test_regex_def2 *list) | 718 void test_regex_list2(const test_regex_def2 *list) |