From 9fc090e795b3de9a2819f98f2205cab21ef41ad8 Mon Sep 17 00:00:00 2001 From: "kts of kettek (nyaa)" Date: Tue, 14 Jan 2020 21:29:20 -0800 Subject: [PATCH] Adjust join_strings logic to not auto free --- common/living.c | 12 +++++++++--- common/shstr.c | 4 +--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/common/living.c b/common/living.c index 884c4b1..3917060 100644 --- a/common/living.c +++ b/common/living.c @@ -1184,7 +1184,9 @@ void fix_object(object *op) { if (tmp->slaying!=NULL) { if (op->slaying != NULL) - op->slaying = join_strings(op->slaying, tmp->slaying, ","); + sstring joined_str = join_strings(op->slaying, tmp->slaying, ","); + free_string(op->slaying); + op->slaying = joined_str; else add_refcount(op->slaying = tmp->slaying); } @@ -1236,7 +1238,9 @@ void fix_object(object *op) { weapon_speed=0; if (tmp->slaying!=NULL) { if (op->slaying != NULL) - op->slaying = join_strings(op->slaying, tmp->slaying, ","); + sstring joined_str = join_strings(op->slaying, tmp->slaying, ","); + free_string(op->slaying); + op->slaying = joined_str; else add_refcount(op->slaying = tmp->slaying); } @@ -1279,7 +1283,9 @@ void fix_object(object *op) { max=ARMOUR_SPEED(tmp)/10.0; if (tmp->slaying!=NULL) { if (op->slaying != NULL) - op->slaying = join_strings(op->slaying, tmp->slaying, ","); + sstring joined_str = join_strings(op->slaying, tmp->slaying, ","); + free_string(op->slaying); + op->slaying = joined_str; else add_refcount(op->slaying = tmp->slaying); } diff --git a/common/shstr.c b/common/shstr.c index 72687f1..5c316eb 100644 --- a/common/shstr.c +++ b/common/shstr.c @@ -237,10 +237,8 @@ sstring join_strings(sstring target_str, sstring source_str, const char *separat /* create shared string from buffer */ ss = add_string(buf); - /* free our buffer and our shared string references */ + /* free our buffer */ free(buf); - free_string(target_str); - free_string(source_str); return ss; }