From 0ece95117339bd58a4bd5af04615a7f1eae2a52a Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Sun, 22 Oct 2023 18:39:14 +0200 Subject: [PATCH] Fix memory corruption on removal of multiple cheats with the same address hash --- Core/cheats.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/cheats.c b/Core/cheats.c index 00c81066c..6201f9f0d 100644 --- a/Core/cheats.c +++ b/Core/cheats.c @@ -132,7 +132,7 @@ void GB_remove_cheat(GB_gameboy_t *gb, const GB_cheat_t *cheat) *hash = NULL; } else { - *hash = malloc(sizeof(GB_cheat_hash_t) + sizeof(cheat) * (*hash)->size); + *hash = realloc(*hash, sizeof(GB_cheat_hash_t) + sizeof(cheat) * (*hash)->size); } break; } @@ -228,7 +228,7 @@ void GB_update_cheat(GB_gameboy_t *gb, const GB_cheat_t *_cheat, const char *des *hash = NULL; } else { - *hash = malloc(sizeof(GB_cheat_hash_t) + sizeof(cheat) * (*hash)->size); + *hash = realloc(*hash, sizeof(GB_cheat_hash_t) + sizeof(cheat) * (*hash)->size); } break; }