summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2018-06-22 23:10:27 -0700
committerMichael Pavone <pavone@retrodev.com>2018-06-22 23:10:27 -0700
commite1d177b8429e4eb59f5a6e853009dbf97ab95068 (patch)
tree4733ff57c8a2fbac7470ca64d89852ae01908686
parente9dcae6c35185d58f41d49b8952f9d55984532fd (diff)
Fix some memory errors (mostly leaks) identified by valgrind
-rw-r--r--blastem.c2
-rw-r--r--genesis.c1
-rw-r--r--m68k_core.c12
-rw-r--r--png.c1
-rw-r--r--romdb.c3
-rw-r--r--util.c3
-rw-r--r--z80_to_x86.c12
7 files changed, 31 insertions, 3 deletions
diff --git a/blastem.c b/blastem.c
index 89d2694..138532b 100644
--- a/blastem.c
+++ b/blastem.c
@@ -259,7 +259,7 @@ void setup_saves(system_media *media, rom_info *info, system_header *context)
//initial save dir was calculated based on lock-on cartridge because that's where the save device is
//save directory used for save states should still be located in the normal place
free(save_dir);
- save_dir = get_save_dir(media);
+ parts[0] = save_dir = get_save_dir(media);
}
if (use_native_states || context->type != SYSTEM_GENESIS) {
parts[2] = "quicksave.state";
diff --git a/genesis.c b/genesis.c
index 0c2d4b4..3fc9895 100644
--- a/genesis.c
+++ b/genesis.c
@@ -1301,7 +1301,6 @@ genesis_context *alloc_init_genesis(rom_info *rom, void *main_rom, void *lock_on
gen->psg = malloc(sizeof(psg_context));
psg_init(gen->psg, gen->master_clock, MCLKS_PER_PSG);
- gen->zram = calloc(1, Z80_RAM_BYTES);
z80_map[0].buffer = gen->zram = calloc(1, Z80_RAM_BYTES);
#ifndef NO_Z80
z80_options *z_opts = malloc(sizeof(z80_options));
diff --git a/m68k_core.c b/m68k_core.c
index eee407a..a118b18 100644
--- a/m68k_core.c
+++ b/m68k_core.c
@@ -1191,7 +1191,19 @@ void m68k_reset(m68k_context * context)
void m68k_options_free(m68k_options *opts)
{
+ for (uint32_t address = 0; address < opts->gen.address_mask; address += NATIVE_CHUNK_SIZE)
+ {
+ uint32_t chunk = address / NATIVE_CHUNK_SIZE;
+ if (opts->gen.native_code_map[chunk].base) {
+ free(opts->gen.native_code_map[chunk].offsets);
+ }
+ }
free(opts->gen.native_code_map);
+ uint32_t ram_inst_slots = ram_size(&opts->gen) / 1024;
+ for (uint32_t i = 0; i < ram_inst_slots; i++)
+ {
+ free(opts->gen.ram_inst_sizes[i]);
+ }
free(opts->gen.ram_inst_sizes);
free(opts);
}
diff --git a/png.c b/png.c
index c1efca7..188bbfe 100644
--- a/png.c
+++ b/png.c
@@ -430,6 +430,7 @@ uint32_t *load_png(uint8_t *buffer, uint32_t buf_size, uint32_t *width, uint32_t
}
last_line = line_start;
}
+ free(decomp_buffer);
} else {
//skip uncrecognized chunks
cur += 4 + chunk_size;
diff --git a/romdb.c b/romdb.c
index f0f7ed3..35e833f 100644
--- a/romdb.c
+++ b/romdb.c
@@ -51,6 +51,8 @@ void free_rom_info(rom_info *info)
free(info->save_buffer);
if (info->save_type == SAVE_I2C) {
free(info->eeprom_map);
+ } else if (info->save_type == SAVE_NOR) {
+ free(info->nor);
}
}
free(info->map);
@@ -58,7 +60,6 @@ void free_rom_info(rom_info *info)
free(info->port2_override);
free(info->ext_override);
free(info->mouse_mode);
- free(info->nor);
}
void cart_serialize(system_header *sys, serialize_buffer *buf)
diff --git a/util.c b/util.c
index 91ee262..4feca66 100644
--- a/util.c
+++ b/util.c
@@ -359,9 +359,11 @@ uint8_t path_matches_extensions(char *path, char **ext_list, uint32_t num_exts)
for (extidx = 0; extidx < num_exts; extidx++)
{
if (!strcasecmp(ext, ext_list[extidx])) {
+ free(ext);
return 1;
}
}
+ free(ext);
return 0;
}
@@ -721,6 +723,7 @@ dir_entry *get_dir_list(char *path, size_t *numret)
if (numret) {
*numret = pos;
}
+ closedir(d);
return ret;
}
diff --git a/z80_to_x86.c b/z80_to_x86.c
index d2341a2..cd51389 100644
--- a/z80_to_x86.c
+++ b/z80_to_x86.c
@@ -3671,7 +3671,19 @@ void z80_run(z80_context * context, uint32_t target_cycle)
void z80_options_free(z80_options *opts)
{
+ for (uint32_t address = 0; address < opts->gen.address_mask; address += NATIVE_CHUNK_SIZE)
+ {
+ uint32_t chunk = address / NATIVE_CHUNK_SIZE;
+ if (opts->gen.native_code_map[chunk].base) {
+ free(opts->gen.native_code_map[chunk].offsets);
+ }
+ }
free(opts->gen.native_code_map);
+ uint32_t ram_inst_slots = ram_size(&opts->gen) / 1024;
+ for (uint32_t i = 0; i < ram_inst_slots; i++)
+ {
+ free(opts->gen.ram_inst_sizes[i]);
+ }
free(opts->gen.ram_inst_sizes);
free(opts);
}