]> git.ozlabs.org Git - ccan/blobdiff - ccan/tal/test/run-free.c
tal: make sure tal_free() preserves errno.
[ccan] / ccan / tal / test / run-free.c
diff --git a/ccan/tal/test/run-free.c b/ccan/tal/test/run-free.c
new file mode 100644 (file)
index 0000000..7b9a086
--- /dev/null
@@ -0,0 +1,25 @@
+#include <ccan/tal/tal.h>
+#include <ccan/tal/tal.c>
+#include <ccan/tap/tap.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();
+}