summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-04-19 09:31:51 -0300
committerEuAndreh <eu@euandre.org>2024-04-19 09:31:51 -0300
commit5cf39c8092aa8540e061a789ea85c87e5de1220d (patch)
tree04412274636dddf8d639b8738914896c9579615c /tests
parenttests/util.c: Add missing free() calls (diff)
downloadpindaiba-5cf39c8092aa8540e061a789ea85c87e5de1220d.tar.gz
pindaiba-5cf39c8092aa8540e061a789ea85c87e5de1220d.tar.xz
src/util.c: Add freeit()
Diffstat (limited to 'tests')
-rw-r--r--tests/util.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/util.c b/tests/util.c
index f4e3d0c..ad43012 100644
--- a/tests/util.c
+++ b/tests/util.c
@@ -62,6 +62,38 @@ out:
return rc;
}
+static int
+test_freeit(void) {
+ int rc = -1;
+
+ test_start("freeit()");
+
+ const char *ptr = NULL;
+
+ {
+ testing("ptr is NULL afterwards");
+
+ ptr = malloc(1234U);
+ if (ptr == NULL) {
+ logerr("malloc(): %s\n", strerror(errno));
+ goto out;
+ }
+
+ assert(ptr != NULL);
+ freeit((void *)&ptr);
+ assert(ptr == NULL);
+
+ test_ok();
+ }
+
+ rc = 0;
+out:
+ if (ptr != NULL) {
+ freeit((void *)&ptr);
+ }
+ return rc;
+}
+
int
main(void) {
@@ -72,6 +104,11 @@ main(void) {
goto out;
}
+ if (test_freeit()) {
+ logerr("test_freeit();\n");
+ goto out;
+ }
+
rc = 0;
out:
return !!rc;