summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2015-07-31 19:56:38 +0200
committerDavid Herrmann <dh.herrmann@gmail.com>2015-07-31 19:56:38 +0200
commit97b11eedff9d2e17101ad453caf9e48b73246719 (patch)
treeadd86c36a039f2cbeb8232908c7a0cb3ca784ea5 /src/test
parentb2a0ac5e5b29c73ca7c0da23369a4769d5a91ddd (diff)
tree-wide: introduce mfree()
Pretty trivial helper which wraps free() but returns NULL, so we can simplify this: free(foobar); foobar = NULL; to this: foobar = mfree(foobar);
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-util.c33
1 files changed, 11 insertions, 22 deletions
diff --git a/src/test/test-util.c b/src/test/test-util.c
index f43433baa1..fde3fa0988 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -714,45 +714,38 @@ static void test_cunescape(void) {
assert_se(cunescape("abc\\\\\\\"\\b\\f\\a\\n\\r\\t\\v\\003\\177\\234\\313\\000\\x00", 0, &unescaped) < 0);
assert_se(cunescape("abc\\\\\\\"\\b\\f\\a\\n\\r\\t\\v\\003\\177\\234\\313\\000\\x00", UNESCAPE_RELAX, &unescaped) >= 0);
assert_se(streq_ptr(unescaped, "abc\\\"\b\f\a\n\r\t\v\003\177\234\313\\000\\x00"));
- free(unescaped);
- unescaped = NULL;
+ unescaped = mfree(unescaped);
/* incomplete sequences */
assert_se(cunescape("\\x0", 0, &unescaped) < 0);
assert_se(cunescape("\\x0", UNESCAPE_RELAX, &unescaped) >= 0);
assert_se(streq_ptr(unescaped, "\\x0"));
- free(unescaped);
- unescaped = NULL;
+ unescaped = mfree(unescaped);
assert_se(cunescape("\\x", 0, &unescaped) < 0);
assert_se(cunescape("\\x", UNESCAPE_RELAX, &unescaped) >= 0);
assert_se(streq_ptr(unescaped, "\\x"));
- free(unescaped);
- unescaped = NULL;
+ unescaped = mfree(unescaped);
assert_se(cunescape("\\", 0, &unescaped) < 0);
assert_se(cunescape("\\", UNESCAPE_RELAX, &unescaped) >= 0);
assert_se(streq_ptr(unescaped, "\\"));
- free(unescaped);
- unescaped = NULL;
+ unescaped = mfree(unescaped);
assert_se(cunescape("\\11", 0, &unescaped) < 0);
assert_se(cunescape("\\11", UNESCAPE_RELAX, &unescaped) >= 0);
assert_se(streq_ptr(unescaped, "\\11"));
- free(unescaped);
- unescaped = NULL;
+ unescaped = mfree(unescaped);
assert_se(cunescape("\\1", 0, &unescaped) < 0);
assert_se(cunescape("\\1", UNESCAPE_RELAX, &unescaped) >= 0);
assert_se(streq_ptr(unescaped, "\\1"));
- free(unescaped);
- unescaped = NULL;
+ unescaped = mfree(unescaped);
assert_se(cunescape("\\u0000", 0, &unescaped) < 0);
assert_se(cunescape("\\u00DF\\U000000df\\u03a0\\U00000041", UNESCAPE_RELAX, &unescaped) >= 0);
assert_se(streq_ptr(unescaped, "ßßΠA"));
- free(unescaped);
- unescaped = NULL;
+ unescaped = mfree(unescaped);
assert_se(cunescape("\\073", 0, &unescaped) >= 0);
assert_se(streq_ptr(unescaped, ";"));
@@ -859,32 +852,28 @@ static void test_read_hostname_config(void) {
write_string_file(path, "foo", WRITE_STRING_FILE_CREATE);
assert_se(read_hostname_config(path, &hostname) == 0);
assert_se(streq(hostname, "foo"));
- free(hostname);
- hostname = NULL;
+ hostname = mfree(hostname);
/* with comment */
write_string_file(path, "# comment\nfoo", WRITE_STRING_FILE_CREATE);
assert_se(read_hostname_config(path, &hostname) == 0);
assert_se(hostname);
assert_se(streq(hostname, "foo"));
- free(hostname);
- hostname = NULL;
+ hostname = mfree(hostname);
/* with comment and extra whitespace */
write_string_file(path, "# comment\n\n foo ", WRITE_STRING_FILE_CREATE);
assert_se(read_hostname_config(path, &hostname) == 0);
assert_se(hostname);
assert_se(streq(hostname, "foo"));
- free(hostname);
- hostname = NULL;
+ hostname = mfree(hostname);
/* cleans up name */
write_string_file(path, "!foo/bar.com", WRITE_STRING_FILE_CREATE);
assert_se(read_hostname_config(path, &hostname) == 0);
assert_se(hostname);
assert_se(streq(hostname, "foobar.com"));
- free(hostname);
- hostname = NULL;
+ hostname = mfree(hostname);
/* no value set */
hostname = (char*) 0x1234;