summaryrefslogtreecommitdiff
path: root/ccan/tal/test/run-free.c
diff options
context:
space:
mode:
authorWilliam Casarin <jb55@jb55.com>2018-07-09 12:10:32 -0700
committerWilliam Casarin <jb55@jb55.com>2018-07-09 12:10:32 -0700
commit1b8fbbd843ddeb5fc81c9303db9c590a436d499b (patch)
treea7227dfe8e4fbaee7b1e0b58b24994dce8078f3f /ccan/tal/test/run-free.c
parent37a9cdd2e80386f2c94e14e4f511284ae14c745a (diff)
progress
Diffstat (limited to 'ccan/tal/test/run-free.c')
-rw-r--r--ccan/tal/test/run-free.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/ccan/tal/test/run-free.c b/ccan/tal/test/run-free.c
new file mode 100644
index 0000000..37d03cd
--- /dev/null
+++ b/ccan/tal/test/run-free.c
@@ -0,0 +1,29 @@
+#include <ccan/tal/tal.h>
+#include <ccan/tal/tal.c>
+#include <ccan/tap/tap.h>
+
+static void destroy_errno(char *p UNNEEDED)
+{
+ /* Errno restored for all the destructors. */
+ ok1(errno == EINVAL);
+ errno = ENOENT;
+}
+
+int main(void)
+{
+ char *p;
+
+ plan_tests(5);
+
+ p = tal(NULL, char);
+ ok1(tal_add_destructor(p, destroy_errno));
+ ok1(tal_add_destructor(p, destroy_errno));
+
+ /* Errno save/restored across free. */
+ errno = EINVAL;
+ tal_free(p);
+ ok1(errno == EINVAL);
+
+ tal_cleanup();
+ return exit_status();
+}