Beispiel #1
0
static bool test_unref_reparent(void)
{
	void *root, *p1, *p2, *c1;

	printf("test: unref_reparent\n# UNREFERENCE AFTER PARENT FREED\n");

	root = talloc_named_const(NULL, 0, "root");
	p1 = talloc_named_const(root, 1, "orig parent");
	p2 = talloc_named_const(root, 1, "parent by reference");

	c1 = talloc_named_const(p1, 1, "child");
	talloc_reference(p2, c1);

	CHECK_PARENT("unref_reparent", c1, p1);

	talloc_free(p1);

	CHECK_PARENT("unref_reparent", c1, p2);

	talloc_unlink(p2, c1);

	CHECK_SIZE("unref_reparent", root, 1);

	talloc_free(p2);
	talloc_free(root);

	printf("success: unref_reparent\n");
	return true;
}
Beispiel #2
0
static bool test_free_parent_reparent_child_in_pool(void)
{
	void *top = talloc_new(NULL);
	char *level1;
	char *alternate_level1;
	char *level2;
	void *pool;
	struct new_parent *level3;

	printf("test: free_parent_reparent_child_in_pool\n# "
		"TALLOC FREE PARENT REPARENT CHILD IN POOL\n");

	pool = talloc_pool(top, 1024);
	level1 = talloc_strdup(pool, "level1");
	alternate_level1 = talloc_strdup(top, "alternate_level1");
	level2 = talloc_strdup(level1, "level2");
	level3 = talloc(level2, struct new_parent);
	level3->new_parent = alternate_level1;
	memset(level3->val, 'x', sizeof(level3->val));

	talloc_set_destructor(level3, reparenting_destructor);
	talloc_free(level1);
	talloc_set_destructor(level3, NULL);

	CHECK_PARENT("free_parent_reparent_child_in_pool",
		level3, alternate_level1);

	/* Even freeing alternate_level1 should leave pool alone. */
	talloc_free(alternate_level1);
	talloc_free(top);

	printf("success: free_parent_reparent_child_in_pool\n");
	return true;
}
Beispiel #3
0
static bool test_free_parent_reparent_child(void)
{
	void *top = talloc_new(NULL);
	char *level1;
	char *alternate_level1;
	char *level2;
	struct new_parent *level3;

	printf("test: free_parent_reparent_child\n# "
		"TALLOC FREE PARENT REPARENT CHILD\n");

	level1 = talloc_strdup(top, "level1");
	alternate_level1 = talloc_strdup(top, "alternate_level1");
	level2 = talloc_strdup(level1, "level2");
	level3 = talloc(level2, struct new_parent);
	level3->new_parent = alternate_level1;
	memset(level3->val, 'x', sizeof(level3->val));

	talloc_set_destructor(level3, reparenting_destructor);
	talloc_free(level1);

	CHECK_PARENT("free_parent_reparent_child",
		level3, alternate_level1);

	talloc_free(top);

	printf("success: free_parent_reparent_child\n");
	return true;
}
static bool test_unref_reparent(const struct torture_context *ctx)
{
	void *root, *p1, *p2, *c1;
	bool ret = false;

	root = talloc_named_const(ctx, 0, "root");
	if (!root)
		goto out;
	p1 = talloc_named_const(root, 1, "orig parent");
	if (!p1)
		goto out;
	p2 = talloc_named_const(root, 1, "parent by reference");
	if (!p2)
		goto out;

	c1 = talloc_named_const(p1, 1, "child");
	if (!c1)
		goto out;

	if (!talloc_reference(p2, c1))
		goto out;

	CHECK_PARENT("unref_reparent", c1, p1);

	talloc_free(p1);

	CHECK_PARENT("unref_reparent", c1, p2);

	talloc_unlink(p2, c1);

	CHECK_SIZE("unref_reparent", root, 1);

	talloc_free(p2);
	ret = true;
out:
 	talloc_free(root);

	return ret;
}
Beispiel #5
0
EAPI Edoors_Room* edoors_room_add(const char* name, const Edoors_Room *parent)
{
    CHECK_PARENT();

    BUILD_INSTANCE(Edoors_Room,room);

    INIT_IOTA(&room->iota,name,parent,EDOORS_TYPE_ROOM);

    ADD_TO_PARENT(parent,(&room->iota),"Room")

    room->links = NULL;    // TODO
    room->children = eina_hash_stringshared_new((Eina_Free_Cb)&edoors_iota_free);

    return room;
}
Beispiel #6
0
static bool test_free_parent_deny_child(void)
{
	void *top = talloc_new(NULL);
	char *level1;
	char *level2;
	char *level3;

	printf("test: free_parent_deny_child\n# TALLOC FREE PARENT DENY CHILD\n");

	level1 = talloc_strdup(top, "level1");
	level2 = talloc_strdup(level1, "level2");
	level3 = talloc_strdup(level2, "level3");

	talloc_set_destructor(level3, fail_destructor_str);
	talloc_free(level1);
	talloc_set_destructor(level3, NULL);

	CHECK_PARENT("free_parent_deny_child", level3, top);

	talloc_free(top);

	printf("success: free_parent_deny_child\n");
	return true;
}