Fix resource leaks

This commit is contained in:
twinaphex 2016-05-23 22:17:28 +02:00
parent 974d3245d2
commit d5d2f7f8ee
13 changed files with 38 additions and 8 deletions

View File

@ -226,6 +226,7 @@ static void *ja_init(const char *device, unsigned rate, unsigned latency)
error:
if (jports != NULL)
jack_free(jports);
free(jd);
return NULL;
}

View File

@ -1955,20 +1955,28 @@ static unsigned cheevos_find_game_id_nes(
{
53, 198, 228
};
bool round = true;
RFILE *file = filestream_open(info->path, RFILE_MODE_READ, 0);
bool round = true;
RFILE *file = NULL;
uint8_t * data = (uint8_t *) malloc(rom_size << 14);
if (!file || !data)
if (!data)
return 0;
file = filestream_open(info->path, RFILE_MODE_READ, 0);
if (!file)
{
free(data);
filestream_close(file);
return 0;
}
/* from fceu core - need it for a correctly md5 sum */
memset(data, 0xFF, rom_size << 14);
/* from fceu core - compute size using the cart mapper */
mapper_no = (header.rom_type >> 4);
mapper_no = (header.rom_type >> 4);
mapper_no |= (header.rom_type2 & 0xF0);
for (i = 0; i != sizeof(not_power2) / sizeof(not_power2[0]); ++i)
{
@ -1977,7 +1985,8 @@ static unsigned cheevos_find_game_id_nes(
* since PRGCartMapping wants ROM_size to be to the power of 2
* so instead if not to power of 2, we just use head.ROM_size when
* we use FCEU_read. */
if (not_power2[i] == mapper_no) {
if (not_power2[i] == mapper_no)
{
round = false;
break;
}

View File

@ -732,5 +732,7 @@ bool core_info_get_display_name(const char *path, char *s, size_t len)
error:
if (core_name)
free(core_name);
if (display_name)
free(display_name);
return false;
}

View File

@ -1050,6 +1050,8 @@ static bool frontend_linux_powerstate_check_acpi_sysfs(
else
*state = FRONTEND_POWERSTATE_ON_POWER_SOURCE;
retro_closedir(entry);
return true;
error:

View File

@ -618,11 +618,10 @@ static bool open_devices(udev_input_t *udev, const char *type, device_handle_cb
{
int fd = open(devnode, O_RDONLY | O_NONBLOCK);
(void)fd;
RARCH_LOG("[udev] Adding device %s as type %s.\n", devnode, type);
if (!add_device(udev, devnode, cb))
RARCH_ERR("[udev] Failed to open device: %s (%s).\n", devnode, strerror(errno));
close(fd);
}
udev_device_unref(dev);

View File

@ -286,6 +286,8 @@ struct http_t *net_http_new(struct http_connection_t *conn)
error:
if (fd >= 0)
socket_close(fd);
if (state)
free(state);
return NULL;
}

View File

@ -650,6 +650,8 @@ int rmsgpack_read(RFILE *fd,
return read_map(fd, (uint32_t)tmp_len, callbacks, data);
}
if (buff)
free(buff);
return 0;
error:

View File

@ -226,7 +226,10 @@ bool cheat_manager_load(const char *path)
cheat = cheat_manager_new(cheats);
if (!cheat)
{
config_file_free(conf);
return false;
}
for (i = 0; i < cheats; i++)
{

View File

@ -180,6 +180,8 @@ static int deferred_push_cursor_manager_list_deferred(
end:
if (conf)
config_file_free(conf);
free(rdb);
free(query);
return ret;
}

View File

@ -353,6 +353,9 @@ static int playlist_association_left(unsigned type, const char *label,
strlcpy(settings->playlist_cores, new_playlist_cores, sizeof(settings->playlist_cores));
string_list_free(stnames);
string_list_free(stcores);
return 0;
}

View File

@ -375,6 +375,8 @@ static int playlist_association_right(unsigned type, const char *label,
strlcpy(settings->playlist_cores, new_playlist_cores, sizeof(settings->playlist_cores));
string_list_free(stnames);
string_list_free(stcores);
return 0;
}

View File

@ -289,6 +289,8 @@ static int action_start_playlist_association(unsigned type, const char *label)
strlcpy(settings->playlist_cores, new_playlist_cores, sizeof(settings->playlist_cores));
string_list_free(stcores);
string_list_free(stnames);
return 0;
}

View File

@ -617,6 +617,7 @@ static int content_file_compressed_read(
if (optional_filename && path_file_exists(optional_filename))
{
*length = 0;
string_list_free(str_list);
return 1;
}