aboutsummaryrefslogtreecommitdiff
path: root/sway/commands.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-05-14 08:00:08 -0400
committerGitHub <noreply@github.com>2018-05-14 08:00:08 -0400
commit4e6cb2b4b2cff21ca1ec751986d8a2e138ea1ed5 (patch)
tree20e1308a555f14212ac246af0cd559d3a37a5065 /sway/commands.c
parent270c1ee7e507f1d2960920a7f4f0cc70f4e13d26 (diff)
parent92b8497a0b7cb866dfea2214625c5a58724aa4d6 (diff)
Merge pull request #1968 from RyanDwyer/fix-criteria
Fix double free in criteria
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c42
1 files changed, 16 insertions, 26 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 37ead367..60c64776 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -12,6 +12,7 @@
#include "sway/security.h"
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
+#include "sway/tree/view.h"
#include "stringop.h"
#include "log.h"
@@ -284,7 +285,7 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
char *head = exec;
char *cmdlist;
char *cmd;
- list_t *containers = NULL;
+ list_t *views = NULL;
if (seat == NULL) {
// passing a NULL seat means we just pick the default seat
@@ -301,31 +302,18 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
// Extract criteria (valid for this command list only).
bool has_criteria = false;
if (*head == '[') {
- has_criteria = true;
- ++head;
- char *criteria_string = argsep(&head, "]");
- if (head) {
- ++head;
- list_t *tokens = create_list();
- char *error;
-
- if ((error = extract_crit_tokens(tokens, criteria_string))) {
- wlr_log(L_DEBUG, "criteria string parse error: %s", error);
- results = cmd_results_new(CMD_INVALID, criteria_string,
- "Can't parse criteria string: %s", error);
- free(error);
- free(tokens);
- goto cleanup;
- }
- containers = container_for_crit_tokens(tokens);
-
- free(tokens);
- } else {
- if (!results) {
- results = cmd_results_new(CMD_INVALID, criteria_string, "Unmatched [");
- }
+ char *error = NULL;
+ struct criteria *criteria = criteria_parse(head, &error);
+ if (!criteria) {
+ results = cmd_results_new(CMD_INVALID, head,
+ "%s", error);
+ free(error);
goto cleanup;
}
+ views = criteria_get_views(criteria);
+ head += strlen(criteria->raw);
+ criteria_destroy(criteria);
+ has_criteria = true;
// Skip leading whitespace
head += strspn(head, whitespace);
}
@@ -382,8 +370,9 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
}
free_cmd_results(res);
} else {
- for (int i = 0; i < containers->length; ++i) {
- config->handler_context.current_container = containers->items[i];
+ for (int i = 0; i < views->length; ++i) {
+ struct sway_view *view = views->items[i];
+ config->handler_context.current_container = view->swayc;
struct cmd_results *res = handler->handle(argc-1, argv+1);
if (res->status != CMD_SUCCESS) {
free_argv(argc, argv);
@@ -401,6 +390,7 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
} while(head);
cleanup:
free(exec);
+ free(views);
if (!results) {
results = cmd_results_new(CMD_SUCCESS, NULL, NULL);
}