]> git.ozlabs.org Git - ccan/blobdiff - ccan/tal/talloc/test/run-free.c
tal/talloc: new module for backending tal onto talloc.
[ccan] / ccan / tal / talloc / test / run-free.c
diff --git a/ccan/tal/talloc/test/run-free.c b/ccan/tal/talloc/test/run-free.c
new file mode 100644 (file)
index 0000000..0dee0a7
--- /dev/null
@@ -0,0 +1,26 @@
+#include <ccan/tal/talloc/talloc.h>
+#include <ccan/tal/talloc/talloc.c>
+#include <ccan/tap/tap.h>
+#include <errno.h>
+
+static void destroy_errno(char *p)
+{
+       errno = ENOENT;
+}
+
+int main(void)
+{
+       char *p;
+
+       plan_tests(2);
+
+       p = tal(NULL, char);
+       ok1(tal_add_destructor(p, destroy_errno));
+
+       /* Errno save/restored across free. */
+       errno = EINVAL;
+       tal_free(p);
+       ok1(errno == EINVAL);
+
+       return exit_status();
+}