diff options
Diffstat (limited to 'worlds')
| -rw-r--r-- | worlds/test.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/worlds/test.c b/worlds/test.c index 3f43a7a..2ce4122 100644 --- a/worlds/test.c +++ b/worlds/test.c @@ -9,7 +9,7 @@ static void portal_init(room_id id) { debugf("portal room init.\n"); struct object_t *new = obj_new("weapon"); - new->name = "sword"; + new->name = strdup("sword"); new->list = true; new->userdata = malloc(sizeof(double)); double p = 3.14159265358979323846L; @@ -99,7 +99,8 @@ const char *shiny(struct object_t *obj, user_t *user) void weap_serialize(int fd, struct object_t *obj) { - write(fd, obj->userdata, sizeof(double)); + if(obj->userdata) + write(fd, obj->userdata, sizeof(double)); } void weap_deserialize(int fd, struct object_t *obj) @@ -108,6 +109,12 @@ void weap_deserialize(int fd, struct object_t *obj) read(fd, obj->userdata, sizeof(double)); } +void weap_destroy(struct object_t *obj) +{ + free(obj->userdata); + obj->userdata = NULL; +} + const struct obj_class_t netcosm_obj_classes[] = { { "weapon", weap_serialize, @@ -115,7 +122,7 @@ const struct obj_class_t netcosm_obj_classes[] = { NULL, NULL, NULL, - NULL, + weap_destroy, shiny }, }; |