{
struct prop_hdr **prop, *p, *next;
+ assert(!taken(from_tal_hdr(t)));
+
/* Already being destroyed? Don't loop. */
if (unlikely(get_destroying_bit(t->parent_child)))
return;
/* Fix up linked list pointers. */
t->list.next->prev = t->list.prev->next = &t->list;
+ /* Copy take() property. */
+ if (taken(from_tal_hdr(old_t)))
+ take(from_tal_hdr(t));
+
/* Fix up child property's parent pointer. */
child = find_property(t, CHILDREN);
if (child) {
* This returns true on success (and may move *@p), or false on failure.
* On success, tal_count() of *@p will be @count.
*
+ * Note: if *p is take(), it will still be take() upon return, even if it
+ * has been moved.
+ *
* Example:
* tal_resize(&p, 100);
*/
--- /dev/null
+#include <ccan/tal/tal.h>
+#include <ccan/tal/tal.c>
+#include <ccan/tap/tap.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+int main(void)
+{
+ int status;
+ char *p;
+
+ plan_tests(4);
+
+ /* Test direct free. */
+ switch (fork()) {
+ case 0:
+ tal_free(take(tal(NULL, char)));
+ exit(2);
+ case -1:
+ exit(1);
+ default:
+ wait(&status);
+ ok1(WIFSIGNALED(status));
+ ok1(WTERMSIG(status) == SIGABRT);
+ }
+
+ /* Test indirect free. */
+ switch (fork()) {
+ case 0:
+ p = tal(NULL, char);
+ take(tal(p, char));
+ tal_free(p);
+ exit(2);
+ case -1:
+ exit(1);
+ default:
+ wait(&status);
+ ok1(WIFSIGNALED(status));
+ ok1(WTERMSIG(status) == SIGABRT);
+ }
+ return exit_status();
+}
{
char *parent, *c;
- plan_tests(21);
+ plan_tests(22);
/* We can take NULL. */
ok1(take(NULL) == NULL);
tal_free(c);
ok1(tal_first(parent) == NULL);
+ /* tal_resize should return a taken pointer. */
+ c = take(tal_arr(parent, char, 5));
+ tal_resize(&c, 100);
+ ok1(taken(c));
+ tal_free(c);
+
tal_free(parent);
ok1(!taken_any());