memory: Add free wrapper and refactor project to use it

We already use wrappers for allocation, the new `xfree` function is the
equivalent for deallocation and provides a way to fully replace the malloc
implementation used by Neovim.
This commit is contained in:
Thiago de Arruda
2015-04-12 11:37:22 -03:00
parent ba10e311bd
commit 34c48aaf12
70 changed files with 1361 additions and 1353 deletions

View File

@@ -478,9 +478,9 @@ static void on_request_event(Event event)
result,
&out_buffer));
// All arguments were freed already, but we still need to free the array
free(args.items);
xfree(args.items);
decref(channel);
free(e);
xfree(e);
}
static bool channel_write(Channel *channel, WBuffer *buffer)
@@ -601,7 +601,7 @@ static void unsubscribe(Channel *channel, char *event)
// Since the string is no longer used by other channels, release it's memory
pmap_del(cstr_t)(event_strings, event_string);
free(event_string);
xfree(event_string);
}
/// Close the channel streams/job and free the channel resources.
@@ -655,13 +655,13 @@ static void free_channel(Channel *channel)
pmap_free(cstr_t)(channel->subscribed_events);
kv_destroy(channel->call_stack);
kv_destroy(channel->delayed_notifications);
free(channel);
xfree(channel);
}
static void close_cb(uv_handle_t *handle)
{
free(handle->data);
free(handle);
xfree(handle->data);
xfree(handle);
}
static Channel *register_channel(void)
@@ -738,7 +738,7 @@ static WBuffer *serialize_request(uint64_t channel_id,
WBuffer *rv = wstream_new_buffer(xmemdup(sbuffer->data, sbuffer->size),
sbuffer->size,
refcount,
free);
xfree);
msgpack_sbuffer_clear(sbuffer);
api_free_array(args);
return rv;
@@ -757,7 +757,7 @@ static WBuffer *serialize_response(uint64_t channel_id,
WBuffer *rv = wstream_new_buffer(xmemdup(sbuffer->data, sbuffer->size),
sbuffer->size,
1, // responses only go though 1 channel
free);
xfree);
msgpack_sbuffer_clear(sbuffer);
api_free_object(arg);
return rv;

View File

@@ -48,9 +48,9 @@ void remote_ui_disconnect(uint64_t channel_id)
// destroy pending screen updates
api_free_array(data->buffer);
pmap_del(uint64_t)(connected_uis, channel_id);
free(ui->data);
xfree(ui->data);
ui_detach(ui);
free(ui);
xfree(ui);
}
static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id,

View File

@@ -57,7 +57,7 @@ bool server_init(void)
if (!os_getenv(LISTEN_ADDRESS_ENV_VAR)) {
char *listen_address = (char *)vim_tempname();
os_setenv(LISTEN_ADDRESS_ENV_VAR, listen_address, 1);
free(listen_address);
xfree(listen_address);
}
return server_start((char *)os_getenv(LISTEN_ADDRESS_ENV_VAR)) == 0;
@@ -256,10 +256,10 @@ static void connection_cb(uv_stream_t *server, int status)
static void free_client(uv_handle_t *handle)
{
free(handle);
xfree(handle);
}
static void free_server(uv_handle_t *handle)
{
free(handle->data);
xfree(handle->data);
}