Code:
/** * Delete an object and free its memory, and set its pointer to NULL */ void object_delete(struct object **obj_address) { struct object *obj = *obj_address; struct object *prev = obj->prev; struct object *next = obj->next; /* Free slays and brands */ if (obj->slays) free_slay(obj->slays); if (obj->brands) free_brand(obj->brands); /* Check any next and previous objects */ if (next) { if (prev) { prev->next = next; next->prev = prev; } else { next->prev = NULL; } } else if (prev) { prev->next = NULL; } /* If we're tracking the object, stop */ if (player && player->upkeep && obj == player->upkeep->object) player->upkeep->object = NULL; mem_free(obj); *obj_address = NULL; }
Leave a comment: