summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2013-07-23 16:45:50 +0200
committerStef Walter <stef@thewalter.net>2013-07-23 23:06:30 +0200
commitb14fc0351c4dd71c5ca71df77e325d2b2a4c0583 (patch)
treec4a47c77a977158b8bd4dcc8f478d6bc34ad233b /common
parentb7cc29a78c3c705374ff25223fe14749ddb076b9 (diff)
Fix various memory leaks exposed by 'make leakcheck'
Diffstat (limited to 'common')
-rw-r--r--common/tests/test-path.c90
1 files changed, 48 insertions, 42 deletions
diff --git a/common/tests/test-path.c b/common/tests/test-path.c
index a6ba54d..57619c8 100644
--- a/common/tests/test-path.c
+++ b/common/tests/test-path.c
@@ -75,34 +75,40 @@ test_base (void)
}
}
-#define check_equals_and_free(ex, ac) \
- do { assert_str_eq (ex, ac); free (ac); } while (0)
+#define assert_str_eq_free(ex, ac) \
+ do { const char *__s1 = (ex); \
+ char *__s2 = (ac); \
+ if (__s1 && __s2 && strcmp (__s1, __s2) == 0) ; else \
+ p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "assertion failed (%s == %s): (%s == %s)", \
+ #ex, #ac, __s1 ? __s1 : "(null)", __s2 ? __s2 : "(null)"); \
+ free (__s2); \
+ } while (0)
static void
test_build (void)
{
#ifdef OS_UNIX
- check_equals_and_free ("/root/second",
- p11_path_build ("/root", "second", NULL));
- check_equals_and_free ("/root/second",
- p11_path_build ("/root", "/second", NULL));
- check_equals_and_free ("/root/second",
- p11_path_build ("/root/", "second", NULL));
- check_equals_and_free ("/root/second/third",
- p11_path_build ("/root", "second", "third", NULL));
- check_equals_and_free ("/root/second/third",
- p11_path_build ("/root", "/second/third", NULL));
+ assert_str_eq_free ("/root/second",
+ p11_path_build ("/root", "second", NULL));
+ assert_str_eq_free ("/root/second",
+ p11_path_build ("/root", "/second", NULL));
+ assert_str_eq_free ("/root/second",
+ p11_path_build ("/root/", "second", NULL));
+ assert_str_eq_free ("/root/second/third",
+ p11_path_build ("/root", "second", "third", NULL));
+ assert_str_eq_free ("/root/second/third",
+ p11_path_build ("/root", "/second/third", NULL));
#else /* OS_WIN32 */
- check_equals_and_free ("C:\\root\\second",
- p11_path_build ("C:\\root", "second", NULL));
- check_equals_and_free ("C:\\root\\second",
- p11_path_build ("C:\\root", "\\second", NULL));
- check_equals_and_free ("C:\\root\\second",
- p11_path_build ("C:\\root\\", "second", NULL));
- check_equals_and_free ("C:\\root\\second\\third",
- p11_path_build ("C:\\root", "second", "third", NULL));
- check_equals_and_free ("C:\\root\\second/third",
- p11_path_build ("C:\\root", "second/third", NULL));
+ assert_str_eq_free ("C:\\root\\second",
+ p11_path_build ("C:\\root", "second", NULL));
+ assert_str_eq_free ("C:\\root\\second",
+ p11_path_build ("C:\\root", "\\second", NULL));
+ assert_str_eq_free ("C:\\root\\second",
+ p11_path_build ("C:\\root\\", "second", NULL));
+ assert_str_eq_free ("C:\\root\\second\\third",
+ p11_path_build ("C:\\root", "second", "third", NULL));
+ assert_str_eq_free ("C:\\root\\second/third",
+ p11_path_build ("C:\\root", "second/third", NULL));
#endif
}
@@ -113,22 +119,22 @@ test_expand (void)
#ifdef OS_UNIX
putenv ("HOME=/home/blah");
- check_equals_and_free ("/home/blah/my/path",
- p11_path_expand ("~/my/path"));
- check_equals_and_free ("/home/blah",
- p11_path_expand ("~"));
+ assert_str_eq_free ("/home/blah/my/path",
+ p11_path_expand ("~/my/path"));
+ assert_str_eq_free ("/home/blah",
+ p11_path_expand ("~"));
putenv ("XDG_CONFIG_HOME=/my");
- check_equals_and_free ("/my/path",
- p11_path_expand ("~/.config/path"));
+ assert_str_eq_free ("/my/path",
+ p11_path_expand ("~/.config/path"));
putenv ("XDG_CONFIG_HOME=");
- check_equals_and_free ("/home/blah/.config/path",
- p11_path_expand ("~/.config/path"));
+ assert_str_eq_free ("/home/blah/.config/path",
+ p11_path_expand ("~/.config/path"));
#else /* OS_WIN32 */
putenv ("HOME=C:\\Users\\blah");
- check_equals_and_free ("C:\\Users\\blah\\path",
- p11_path_expand ("~/my/path"));
- check_equals_and_free ("C:\\Users\\blah\\path",
- p11_path_expand ("~\\path"));
+ assert_str_eq_free ("C:\\Users\\blah\\path",
+ p11_path_expand ("~/my/path"));
+ assert_str_eq_free ("C:\\Users\\blah\\path",
+ p11_path_expand ("~\\path"));
#endif
putenv("HOME=");
@@ -153,14 +159,14 @@ test_absolute (void)
static void
test_parent (void)
{
- check_equals_and_free ("/", p11_path_parent ("/root"));
- check_equals_and_free ("/", p11_path_parent ("/root/"));
- check_equals_and_free ("/", p11_path_parent ("/root//"));
- check_equals_and_free ("/root", p11_path_parent ("/root/second"));
- check_equals_and_free ("/root", p11_path_parent ("/root//second"));
- check_equals_and_free ("/root", p11_path_parent ("/root//second//"));
- check_equals_and_free ("/root", p11_path_parent ("/root///second"));
- check_equals_and_free ("/root/second", p11_path_parent ("/root/second/test.file"));
+ assert_str_eq_free ("/", p11_path_parent ("/root"));
+ assert_str_eq_free ("/", p11_path_parent ("/root/"));
+ assert_str_eq_free ("/", p11_path_parent ("/root//"));
+ assert_str_eq_free ("/root", p11_path_parent ("/root/second"));
+ assert_str_eq_free ("/root", p11_path_parent ("/root//second"));
+ assert_str_eq_free ("/root", p11_path_parent ("/root//second//"));
+ assert_str_eq_free ("/root", p11_path_parent ("/root///second"));
+ assert_str_eq_free ("/root/second", p11_path_parent ("/root/second/test.file"));
assert_ptr_eq (NULL, p11_path_parent ("/"));
assert_ptr_eq (NULL, p11_path_parent ("//"));
assert_ptr_eq (NULL, p11_path_parent (""));