Avoid rare memory leak.

Technically, a user could pass invalid JSON with duplicate keys to
restore and trigger a memory leak.
This commit is contained in:
Steven Allen 2015-12-20 11:29:55 -08:00
parent bcbee11cf1
commit e434521fc3

View file

@ -109,6 +109,7 @@ bool restore_tree(const char *file_path)
for (int i = 0; i < num; i++) { for (int i = 0; i < num; i++) {
if (keyeq("focusedMonitorName", t, json)) { if (keyeq("focusedMonitorName", t, json)) {
free(focusedMonitorName);
focusedMonitorName = copy_string(t+1, json); focusedMonitorName = copy_string(t+1, json);
t++; t++;
} else if (keyeq("numClients", t, json)) { } else if (keyeq("numClients", t, json)) {
@ -208,6 +209,7 @@ monitor_t *restore_monitor(jsmntok_t **t, char *json)
update_root(m, &m->rectangle); update_root(m, &m->rectangle);
continue; continue;
} else if (keyeq("focusedDesktopName", *t, json)) { } else if (keyeq("focusedDesktopName", *t, json)) {
free(focusedDesktopName);
(*t)++; (*t)++;
focusedDesktopName = copy_string(*t, json); focusedDesktopName = copy_string(*t, json);
} else if (keyeq("desktops", *t, json)) { } else if (keyeq("desktops", *t, json)) {