]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
decrease reference count, so that memory is freed
authorAlan T. DeKok <aland@freeradius.org>
Sun, 29 Mar 2026 19:22:07 +0000 (15:22 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 29 Mar 2026 19:22:40 +0000 (15:22 -0400)
src/lib/util/test/talloc_tests.c

index 16550f9d083135c6044e0cbed7592695e49db8c7..8ee735d954ebec82682a07bc8561f6f47cad2ee4 100644 (file)
@@ -691,7 +691,21 @@ static void test_talloc_increase_ref_count(void)
        TEST_CHECK(ret == 0);
        TEST_CHECK(talloc_reference_count(str) == 2);
 
-       talloc_free(ctx);
+       /*
+        *      And then  decrease it to be safe.
+        */
+       ret = talloc_decrease_ref_count(str);
+       TEST_CHECK(ret == 2);                           // WAS 2
+       TEST_CHECK(talloc_reference_count(str) == 1);   // NOW 1
+
+       ret = talloc_decrease_ref_count(str);
+       TEST_CHECK(ret == 1);                           // WAS 1, now 0 and freed
+
+       ret = talloc_total_blocks(ctx);
+       TEST_CHECK(ret == 1);                           // just ctx itself
+
+       ret = talloc_free(ctx);
+       TEST_CHECK(ret == 0);
 }
 
 /*