struct Match *current_swallow;
static bool swallow_is_empty;
static int num_marks;
-static char **marks;
+/* We need to save each container that needs to be marked if we want to support
+ * marking non-leaf containers. In their case, the end_map for their children is
+ * called before their own end_map, so marking json_node would end up marking
+ * the latest child. We can't just mark containers immediately after we parse a
+ * mark because of #2511. */
+struct pending_marks {
+ char *mark;
+ Con *con_to_be_marked;
+} * marks;
/* This list is used for reordering the focus stack after parsing the 'focus'
* array. */
if (num_marks > 0) {
for (int i = 0; i < num_marks; i++) {
- con_mark(json_node, marks[i], MM_ADD);
- free(marks[i]);
+ Con *con = marks[i].con_to_be_marked;
+ char *mark = marks[i].mark;
+ con_mark(con, mark, MM_ADD);
+ free(mark);
}
FREE(marks);
char *mark;
sasprintf(&mark, "%.*s", (int)len, val);
- marks = srealloc(marks, (++num_marks) * sizeof(char *));
- marks[num_marks - 1] = sstrdup(mark);
+ marks = srealloc(marks, (++num_marks) * sizeof(struct pending_marks));
+ marks[num_marks - 1].mark = sstrdup(mark);
+ marks[num_marks - 1].con_to_be_marked = json_node;
} else {
if (strcasecmp(last_key, "name") == 0) {
json_node->name = scalloc(len + 1, 1);