mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 20:45:14 +00:00
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
This commit is contained in:
parent
09fe9f4542
commit
55d338b66f
Notes:
sideshowbarker
2024-07-18 18:11:19 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/55d338b66f3 Pull-request: https://github.com/SerenityOS/serenity/pull/7060 Issue: https://github.com/SerenityOS/serenity/issues/4592
1 changed files with 14 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue