Merge pull request #2206 from martinetd/leaks

Fix a bunch of leaks
This commit is contained in:
Drew DeVault 2018-07-06 08:43:33 -07:00 committed by GitHub
commit 817e847749
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 30 additions and 11 deletions

View file

@ -79,7 +79,7 @@ void free_cmd_results(struct cmd_results *results);
* *
* Free the JSON string later on. * Free the JSON string later on.
*/ */
const char *cmd_results_to_json(struct cmd_results *results); char *cmd_results_to_json(struct cmd_results *results);
struct cmd_results *add_color(const char *name, struct cmd_results *add_color(const char *name,
char *buffer, const char *color); char *buffer, const char *color);

View file

@ -527,7 +527,7 @@ void free_cmd_results(struct cmd_results *results) {
free(results); free(results);
} }
const char *cmd_results_to_json(struct cmd_results *results) { char *cmd_results_to_json(struct cmd_results *results) {
json_object *result_array = json_object_new_array(); json_object *result_array = json_object_new_array();
json_object *root = json_object_new_object(); json_object *root = json_object_new_object();
json_object_object_add(root, "success", json_object_object_add(root, "success",
@ -542,9 +542,9 @@ const char *cmd_results_to_json(struct cmd_results *results) {
} }
json_object_array_add(result_array, root); json_object_array_add(result_array, root);
const char *json = json_object_to_json_string(result_array); const char *json = json_object_to_json_string(result_array);
free(result_array); char *res = strdup(json);
free(root); json_object_put(result_array);
return json; return res;
} }
/** /**

View file

@ -87,7 +87,12 @@ void free_config(struct sway_config *config) {
list_free(config->cmd_queue); list_free(config->cmd_queue);
list_free(config->workspace_outputs); list_free(config->workspace_outputs);
list_free(config->pid_workspaces); list_free(config->pid_workspaces);
list_free(config->output_configs); if (config->output_configs) {
for (int i = 0; i < config->output_configs->length; i++) {
free_output_config(config->output_configs->items[i]);
}
list_free(config->output_configs);
}
if (config->input_configs) { if (config->input_configs) {
for (int i = 0; i < config->input_configs->length; i++) { for (int i = 0; i < config->input_configs->length; i++) {
free_input_config(config->input_configs->items[i]); free_input_config(config->input_configs->items[i]);

View file

@ -30,6 +30,7 @@ void free_bar_config(struct bar_config *bar) {
if (!bar) { if (!bar) {
return; return;
} }
free(bar->id);
free(bar->mode); free(bar->mode);
free(bar->position); free(bar->position);
free(bar->hidden_state); free(bar->hidden_state);

View file

@ -420,6 +420,9 @@ void sway_keyboard_destroy(struct sway_keyboard *keyboard) {
if (!keyboard) { if (!keyboard) {
return; return;
} }
if (keyboard->keymap) {
xkb_keymap_unref(keyboard->keymap);
}
wl_list_remove(&keyboard->keyboard_key.link); wl_list_remove(&keyboard->keyboard_key.link);
wl_list_remove(&keyboard->keyboard_modifiers.link); wl_list_remove(&keyboard->keyboard_modifiers.link);
free(keyboard); free(keyboard);

View file

@ -64,6 +64,10 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
close(ipc_socket); close(ipc_socket);
unlink(ipc_sockaddr->sun_path); unlink(ipc_sockaddr->sun_path);
while (ipc_client_list->length) {
struct ipc_client *client = ipc_client_list->items[0];
ipc_client_disconnect(client);
}
list_free(ipc_client_list); list_free(ipc_client_list);
if (ipc_sockaddr) { if (ipc_sockaddr) {
@ -479,10 +483,10 @@ void ipc_client_handle_command(struct ipc_client *client) {
case IPC_COMMAND: case IPC_COMMAND:
{ {
struct cmd_results *results = execute_command(buf, NULL); struct cmd_results *results = execute_command(buf, NULL);
const char *json = cmd_results_to_json(results); char *json = cmd_results_to_json(results);
char reply[256]; int length = strlen(json);
int length = snprintf(reply, sizeof(reply), "%s", json); client_valid = ipc_send_reply(client, json, (uint32_t)length);
client_valid = ipc_send_reply(client, reply, (uint32_t)length); free(json);
free_cmd_results(results); free_cmd_results(results);
goto exit_cleanup; goto exit_cleanup;
} }

View file

@ -1,6 +1,7 @@
#define _XOPEN_SOURCE 700 #define _XOPEN_SOURCE 700
#define _POSIX_C_SOURCE 200112L #define _POSIX_C_SOURCE 200112L
#include <getopt.h> #include <getopt.h>
#include <pango/pangocairo.h>
#include <signal.h> #include <signal.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
@ -441,5 +442,7 @@ int main(int argc, char **argv) {
free_config(config); free_config(config);
} }
pango_cairo_font_map_set_default(NULL);
return exit_value; return exit_value;
} }

View file

@ -151,6 +151,7 @@ void container_free(struct sway_container *cont) {
return; return;
} }
free(cont->name); free(cont->name);
free(cont->formatted_title);
wlr_texture_destroy(cont->title_focused); wlr_texture_destroy(cont->title_focused);
wlr_texture_destroy(cont->title_focused_inactive); wlr_texture_destroy(cont->title_focused_inactive);
wlr_texture_destroy(cont->title_unfocused); wlr_texture_destroy(cont->title_unfocused);

View file

@ -514,7 +514,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
if (container_is_floating(focus)) { if (container_is_floating(focus)) {
focus = focus->parent->parent; focus = focus->parent->parent;
} }
free(criterias); list_free(criterias);
cont = container_view_create(focus, view); cont = container_view_create(focus, view);
view->surface = wlr_surface; view->surface = wlr_surface;

View file

@ -191,6 +191,8 @@ char *workspace_next_name(const char *output_name) {
free(target); free(target);
target = _target; target = _target;
wlr_log(L_DEBUG, "Workspace: Found free name %s", _target); wlr_log(L_DEBUG, "Workspace: Found free name %s", _target);
} else {
free(_target);
} }
} }
free(dup); free(dup);