mirror of
https://github.com/libretro/RetroArch.git
synced 2025-02-15 23:19:24 +00:00
(libretro-common) Avoid more callocs
This commit is contained in:
parent
1a625f32e8
commit
5a0bc479b1
@ -84,25 +84,29 @@ static void file_archive_free(file_archive_file_data_t *data)
|
|||||||
|
|
||||||
static file_archive_file_data_t* file_archive_open(const char *path)
|
static file_archive_file_data_t* file_archive_open(const char *path)
|
||||||
{
|
{
|
||||||
file_archive_file_data_t *data = (file_archive_file_data_t*)calloc(1, sizeof(*data));
|
file_archive_file_data_t *data = (file_archive_file_data_t*)
|
||||||
|
malloc(sizeof(*data));
|
||||||
|
|
||||||
if (!data)
|
if (!data)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
data->fd = open(path, O_RDONLY);
|
data->fd = open(path, O_RDONLY);
|
||||||
|
data->data = NULL;
|
||||||
|
data->size = 0;
|
||||||
|
|
||||||
/* Failed to open archive. */
|
/* Failed to open archive. */
|
||||||
if (data->fd < 0)
|
if (data->fd < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
data->size = path_get_size(path);
|
data->size = path_get_size(path);
|
||||||
if (!data->size)
|
if (!data->size)
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
data->data = mmap(NULL, data->size, PROT_READ, MAP_SHARED, data->fd, 0);
|
data->data = mmap(NULL,
|
||||||
|
data->size, PROT_READ, MAP_SHARED, data->fd, 0);
|
||||||
if (data->data == MAP_FAILED)
|
if (data->data == MAP_FAILED)
|
||||||
{
|
{
|
||||||
data->data = NULL;
|
data->data = NULL;
|
||||||
|
|
||||||
/* Failed to mmap() file */
|
/* Failed to mmap() file */
|
||||||
goto error;
|
goto error;
|
||||||
@ -128,21 +132,24 @@ static void file_archive_free(file_archive_file_data_t *data)
|
|||||||
|
|
||||||
static file_archive_file_data_t* file_archive_open(const char *path)
|
static file_archive_file_data_t* file_archive_open(const char *path)
|
||||||
{
|
{
|
||||||
int64_t ret = -1;
|
int64_t ret = -1;
|
||||||
bool read_from_file = false;
|
bool read_from_file = false;
|
||||||
file_archive_file_data_t *data = (file_archive_file_data_t*)
|
file_archive_file_data_t *data = (file_archive_file_data_t*)
|
||||||
calloc(1, sizeof(*data));
|
malloc(sizeof(*data));
|
||||||
|
|
||||||
if (!data)
|
if (!data)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
read_from_file = filestream_read_file(path, &data->data, &ret);
|
data->data = NULL;
|
||||||
|
data->size = 0;
|
||||||
|
read_from_file = filestream_read_file(
|
||||||
|
path, &data->data, &ret);
|
||||||
|
|
||||||
/* Failed to open archive? */
|
/* Failed to open archive? */
|
||||||
if (!read_from_file || ret < 0)
|
if (!read_from_file || ret < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
data->size = ret;
|
data->size = ret;
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -89,6 +89,7 @@ struct http_connection_t
|
|||||||
struct http_socket_state_t sock_state;
|
struct http_socket_state_t sock_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* TODO/FIXME - static globals */
|
||||||
static char urlencode_lut[256];
|
static char urlencode_lut[256];
|
||||||
static bool urlencode_lut_inited = false;
|
static bool urlencode_lut_inited = false;
|
||||||
|
|
||||||
@ -116,9 +117,8 @@ void net_http_urlencode(char **dest, const char *source)
|
|||||||
if (!urlencode_lut_inited)
|
if (!urlencode_lut_inited)
|
||||||
urlencode_lut_init();
|
urlencode_lut_init();
|
||||||
|
|
||||||
enc = (char*)calloc(1, len);
|
enc = (char*)calloc(1, len);
|
||||||
|
*dest = enc;
|
||||||
*dest = enc;
|
|
||||||
|
|
||||||
for (; *source; source++)
|
for (; *source; source++)
|
||||||
{
|
{
|
||||||
@ -252,7 +252,7 @@ static void net_http_send_str(
|
|||||||
struct http_connection_t *net_http_connection_new(const char *url,
|
struct http_connection_t *net_http_connection_new(const char *url,
|
||||||
const char *method, const char *data)
|
const char *method, const char *data)
|
||||||
{
|
{
|
||||||
struct http_connection_t *conn = (struct http_connection_t*)calloc(1,
|
struct http_connection_t *conn = (struct http_connection_t*)malloc(
|
||||||
sizeof(*conn));
|
sizeof(*conn));
|
||||||
|
|
||||||
if (!conn)
|
if (!conn)
|
||||||
@ -264,6 +264,19 @@ struct http_connection_t *net_http_connection_new(const char *url,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conn->domain = NULL;
|
||||||
|
conn->location = NULL;
|
||||||
|
conn->urlcopy = NULL;
|
||||||
|
conn->scan = NULL;
|
||||||
|
conn->methodcopy = NULL;
|
||||||
|
conn->contenttypecopy = NULL;
|
||||||
|
conn->postdatacopy = NULL;
|
||||||
|
conn->useragentcopy = NULL;
|
||||||
|
conn->port = 0;
|
||||||
|
conn->sock_state.fd = 0;
|
||||||
|
conn->sock_state.ssl = false;
|
||||||
|
conn->sock_state.ssl_ctx= NULL;
|
||||||
|
|
||||||
if (method)
|
if (method)
|
||||||
conn->methodcopy = strdup(method);
|
conn->methodcopy = strdup(method);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user