diff options
author | Andrew Kaster <andrewdkaster@gmail.com> | 2021-05-12 04:48:03 -0600 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-05-14 08:34:00 +0100 |
commit | 55d338b66f3c3404baa38d3954f63b38ee813af5 (patch) | |
tree | fc0e6853519d6bfb537565a9c4c7134647aa7597 | |
parent | 09fe9f4542bdada7369a19f5c3fc3b9c0b21969f (diff) | |
download | serenity-55d338b66f3c3404baa38d3954f63b38ee813af5.zip |
Tests: Free all memory allocated with regcomp in RegexLibC tests
The C interface (posix interface?) for regexes has no "initialize"
function, only a free function. The comment in regcomp in
LibRegex/C/Regex.cpp notes that calling regcomp without a regfree is an
error, and will leak memory. Every single time regcomp is called on a
regex_t*, it will allocate new memory.
Make sure that all the regcomp calls are paired with a regfree in the
tests program
-rw-r--r-- | Tests/LibRegex/RegexLibC.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Tests/LibRegex/RegexLibC.cpp b/Tests/LibRegex/RegexLibC.cpp index bea5e5984c..3df9837031 100644 --- a/Tests/LibRegex/RegexLibC.cpp +++ b/Tests/LibRegex/RegexLibC.cpp @@ -327,6 +327,7 @@ TEST_CASE(parser_error_special_characters_used_at_wrong_place) pattern = b.build(); EXPECT_EQ(regcomp(®ex, pattern.characters(), REG_EXTENDED), error_code_to_check); EXPECT_EQ(regexec(®ex, "test", num_matches, matches, 0), error_code_to_check); + regfree(®ex); // After vertical line b.clear(); @@ -335,6 +336,7 @@ TEST_CASE(parser_error_special_characters_used_at_wrong_place) pattern = b.build(); EXPECT_EQ(regcomp(®ex, pattern.characters(), REG_EXTENDED), error_code_to_check); EXPECT_EQ(regexec(®ex, "test", num_matches, matches, 0), error_code_to_check); + regfree(®ex); // After circumflex b.clear(); @@ -343,6 +345,7 @@ TEST_CASE(parser_error_special_characters_used_at_wrong_place) pattern = b.build(); EXPECT_EQ(regcomp(®ex, pattern.characters(), REG_EXTENDED), error_code_to_check); EXPECT_EQ(regexec(®ex, "test", num_matches, matches, 0), error_code_to_check); + regfree(®ex); // After dollar b.clear(); @@ -351,6 +354,7 @@ TEST_CASE(parser_error_special_characters_used_at_wrong_place) pattern = b.build(); EXPECT_EQ(regcomp(®ex, pattern.characters(), REG_EXTENDED), error_code_to_check); EXPECT_EQ(regexec(®ex, "test", num_matches, matches, 0), error_code_to_check); + regfree(®ex); // After left parens b.clear(); @@ -360,9 +364,8 @@ TEST_CASE(parser_error_special_characters_used_at_wrong_place) pattern = b.build(); EXPECT_EQ(regcomp(®ex, pattern.characters(), REG_EXTENDED), error_code_to_check); EXPECT_EQ(regexec(®ex, "test", num_matches, matches, 0), error_code_to_check); + regfree(®ex); } - - regfree(®ex); } TEST_CASE(parser_error_vertical_line_used_at_wrong_place) @@ -376,22 +379,24 @@ TEST_CASE(parser_error_vertical_line_used_at_wrong_place) pattern = "|asdf"; EXPECT_EQ(regcomp(®ex, pattern.characters(), REG_EXTENDED), REG_EMPTY_EXPR); EXPECT_EQ(regexec(®ex, "test", num_matches, matches, 0), REG_EMPTY_EXPR); + regfree(®ex); // Last in ere pattern = "asdf|"; EXPECT_EQ(regcomp(®ex, pattern.characters(), REG_EXTENDED), REG_EMPTY_EXPR); EXPECT_EQ(regexec(®ex, "test", num_matches, matches, 0), REG_EMPTY_EXPR); + regfree(®ex); // After left parens pattern = "(|asdf)"; EXPECT_EQ(regcomp(®ex, pattern.characters(), REG_EXTENDED), REG_EMPTY_EXPR); EXPECT_EQ(regexec(®ex, "test", num_matches, matches, 0), REG_EMPTY_EXPR); + regfree(®ex); // Proceed right parens pattern = "(asdf)|"; EXPECT_EQ(regcomp(®ex, pattern.characters(), REG_EXTENDED), REG_EMPTY_EXPR); EXPECT_EQ(regexec(®ex, "test", num_matches, matches, 0), REG_EMPTY_EXPR); - regfree(®ex); } @@ -969,6 +974,7 @@ TEST_CASE(simple_bracket_chars) EXPECT_EQ(regexec(®ex, "c", 0, NULL, 0), REG_NOERR); EXPECT_EQ(regexec(®ex, "d", 0, NULL, 0), REG_NOMATCH); EXPECT_EQ(regexec(®ex, "e", 0, NULL, 0), REG_NOMATCH); + regfree(®ex); } TEST_CASE(simple_bracket_chars_inverse) @@ -982,6 +988,7 @@ TEST_CASE(simple_bracket_chars_inverse) EXPECT_EQ(regexec(®ex, "c", 0, NULL, 0), REG_NOMATCH); EXPECT_EQ(regexec(®ex, "d", 0, NULL, 0), REG_NOERR); EXPECT_EQ(regexec(®ex, "e", 0, NULL, 0), REG_NOERR); + regfree(®ex); } TEST_CASE(simple_bracket_chars_range) @@ -995,6 +1002,7 @@ TEST_CASE(simple_bracket_chars_range) EXPECT_EQ(regexec(®ex, "c", 0, NULL, 0), REG_NOERR); EXPECT_EQ(regexec(®ex, "d", 0, NULL, 0), REG_NOERR); EXPECT_EQ(regexec(®ex, "e", 0, NULL, 0), REG_NOMATCH); + regfree(®ex); } TEST_CASE(simple_bracket_chars_range_inverse) @@ -1010,6 +1018,7 @@ TEST_CASE(simple_bracket_chars_range_inverse) EXPECT_EQ(regexec(®ex, "e", 0, NULL, 0), REG_NOERR); EXPECT_EQ(regexec(®ex, "k", 0, NULL, 0), REG_NOMATCH); EXPECT_EQ(regexec(®ex, "z", 0, NULL, 0), REG_NOMATCH); + regfree(®ex); } TEST_CASE(bracket_character_class_uuid) @@ -1035,6 +1044,7 @@ TEST_CASE(simple_bracket_character_class_inverse) EXPECT_EQ(regexec(®ex, "3", 0, NULL, 0), REG_NOMATCH); EXPECT_EQ(regexec(®ex, "d", 0, NULL, 0), REG_NOERR); EXPECT_EQ(regexec(®ex, "e", 0, NULL, 0), REG_NOERR); + regfree(®ex); } TEST_CASE(email_address) @@ -1115,4 +1125,5 @@ TEST_CASE(simple_notbol_noteol) EXPECT_EQ(regexec(®ex2, "hello friends", 0, NULL, REG_NOTEOL), REG_NOMATCH); regfree(®ex); + regfree(®ex2); } |