Merge pull request #1591 from dlrobertson/fix_mem_errors

Fix memory errors
This commit is contained in:
Drew DeVault 2018-02-11 11:37:06 -05:00 committed by GitHub
commit 4a76d06f33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View file

@ -36,7 +36,7 @@ char *read_line(FILE *file) {
} }
string[length++] = c; string[length++] = c;
} }
if (length + 1 == size) { if (length + 1 >= size) {
char *new_string = realloc(string, length + 1); char *new_string = realloc(string, length + 1);
if (!new_string) { if (!new_string) {
free(string); free(string);

View file

@ -484,6 +484,8 @@ static bool handle_view_created(wlc_handle handle) {
// refocus in-between command lists // refocus in-between command lists
set_focused_container(newview); set_focused_container(newview);
} }
// Make sure to free the list_t returned by criteria_for.
list_free(criteria);
swayc_t *workspace = swayc_parent_by_type(focused, C_WORKSPACE); swayc_t *workspace = swayc_parent_by_type(focused, C_WORKSPACE);
if (workspace && workspace->fullscreen) { if (workspace && workspace->fullscreen) {
set_focused_container(workspace->fullscreen); set_focused_container(workspace->fullscreen);

View file

@ -1127,7 +1127,7 @@ static void ipc_event_binding(json_object *sb_obj) {
json_object *obj = json_object_new_object(); json_object *obj = json_object_new_object();
json_object_object_add(obj, "change", json_object_new_string("run")); json_object_object_add(obj, "change", json_object_new_string("run"));
// sb_obj gets owned by the temporary json_object, too. // sb_obj gets owned by the temporary json_object, too.
json_object_object_add(obj, "binding", json_object_get(sb_obj)); json_object_object_add(obj, "binding", sb_obj);
const char *json_string = json_object_to_json_string(obj); const char *json_string = json_object_to_json_string(obj);
ipc_send_event(json_string, IPC_EVENT_BINDING); ipc_send_event(json_string, IPC_EVENT_BINDING);
@ -1171,9 +1171,13 @@ void ipc_event_binding_keyboard(struct sway_binding *sb) {
keysym = *(uint32_t *)sb->keys->items[i]; keysym = *(uint32_t *)sb->keys->items[i];
if (xkb_keysym_get_name(keysym, buffer, 64) > 0) { if (xkb_keysym_get_name(keysym, buffer, 64) > 0) {
json_object *str = json_object_new_string(buffer); json_object *str = json_object_new_string(buffer);
json_object_array_add(symbols, str);
if (i == 0) { if (i == 0) {
// str is owned by both symbol and symbols. Make sure
// to bump the ref count.
json_object_array_add(symbols, json_object_get(str));
symbol = str; symbol = str;
} else {
json_object_array_add(symbols, str);
} }
} }
} }