add: if (self->destructor) self->destructor(ptr->data);
context: static void *replaceInBag(WMBag *self, int index, void *item){    W_Node *ptr = treeSearch(SELF->root, SELF->nil, index);    void *old = NULL;    if (item == NULL) {	SELF->count--;		ptr = rbTreeDelete(SELF, ptr);	free(ptr);    } else if (ptr != SELF->nil) {	old = ptr->data;	ptr->data = item;    } else {	W_Node *ptr;	ptr = wmalloc(sizeof(W_Node));	ptr->data = item;	ptr->index = index;	ptr->left = SELF->nil;	ptr->right = SELF->nil;	ptr->parent = SELF->nil;	rbTreeInsert(SELF, ptr);	SELF->count++;    }        return old;}