From 0f7caa610c5ecc69ec1491ff156a7a3a6c51f7a3 Mon Sep 17 00:00:00 2001 From: backwardsEric Date: Fri, 8 Nov 2019 22:32:51 -0800 Subject: [PATCH] Wipe temporary objects used in selling to plug potential leaks of memory allocated for slays, brands, and curses. --- src/store.c | 15 ++++++++++++++- src/ui-store.c | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/store.c b/src/store.c index 259c6dae..65e65f2d 100644 --- a/src/store.c +++ b/src/store.c @@ -1863,6 +1863,7 @@ void do_cmd_sell(struct command *cmd) /* Check if the store has space for the items */ if (!store_check_num(store, &dummy_item)) { + object_wipe(&dummy_item); msg("I have not the room in my store to keep it."); return; } @@ -1891,6 +1892,11 @@ void do_cmd_sell(struct command *cmd) /* Get the "apparent" value */ dummy = object_value(&dummy_item, amt); + /* + * Do not need the dummy any more so release the memory allocated + * within it. + */ + object_wipe(&dummy_item); /* Know flavor of consumables */ object_flavor_aware(obj); @@ -1953,6 +1959,7 @@ void do_cmd_stash(struct command *cmd) struct object *obj, *dropped; bool none_left = false; + bool no_room; if (cmd_get_arg_item(cmd, "item", &obj)) return; @@ -1975,7 +1982,13 @@ void do_cmd_stash(struct command *cmd) /* Get a copy of the object representing the number being sold */ object_copy_amt(&dummy, obj, amt); - if (!store_check_num(store, &dummy)) { + no_room = !store_check_num(store, &dummy); + /* + * Do not need the dummy any more so release the memory allocated + * within it. + */ + object_wipe(&dummy); + if (no_room) { msg("Your home is full."); return; } diff --git a/src/ui-store.c b/src/ui-store.c index 01ecce8a..7ca8b926 100644 --- a/src/ui-store.c +++ b/src/ui-store.c @@ -524,6 +524,7 @@ static bool store_sell(struct store_context *ctx) object_copy_amt(temp_obj, obj, amt); if (!store_check_num(store, temp_obj)) { + object_wipe(temp_obj); if (store->sidx == STORE_HOME) msg("Your home is full."); else @@ -540,6 +541,7 @@ static bool store_sell(struct store_context *ctx) /* Extract the value of the items */ u32b price = price_item(store, temp_obj, true, amt); + object_wipe(temp_obj); screen_save(); /* Show price */ @@ -559,6 +561,7 @@ static bool store_sell(struct store_context *ctx) cmd_set_arg_item(cmdq_peek(), "item", obj); cmd_set_arg_number(cmdq_peek(), "quantity", amt); } else { /* Player is at home */ + object_wipe(temp_obj); cmdq_push(CMD_STASH); cmd_set_arg_item(cmdq_peek(), "item", obj); cmd_set_arg_number(cmdq_peek(), "quantity", amt); -- 2.21.0 (Apple Git-122.2)