diff options
author | Ryan Dwyer <RyanDwyer@users.noreply.github.com> | 2018-09-28 18:27:01 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-28 18:27:01 +1000 |
commit | 5104bd2c5995ed5f4baf7890e6b15263c981721e (patch) | |
tree | d77343ea5c7acb874a85b2906787b7e045ce41b1 | |
parent | Merge pull request #2719 from RyanDwyer/fix-view-is-visible (diff) | |
parent | transaction: do not use pointers for state (diff) | |
download | sway-5104bd2c5995ed5f4baf7890e6b15263c981721e.tar.gz sway-5104bd2c5995ed5f4baf7890e6b15263c981721e.tar.zst sway-5104bd2c5995ed5f4baf7890e6b15263c981721e.zip |
Merge pull request #2663 from ianyfan/fix-txn-state-leaks
Free transaction state upon destruction by removing pointer indirection
-rw-r--r-- | sway/desktop/transaction.c | 55 |
1 files changed, 18 insertions, 37 deletions
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c index 797f6b4c..34d99d52 100644 --- a/sway/desktop/transaction.c +++ b/sway/desktop/transaction.c | |||
@@ -31,14 +31,14 @@ struct sway_transaction_instruction { | |||
31 | struct sway_transaction *transaction; | 31 | struct sway_transaction *transaction; |
32 | struct sway_node *node; | 32 | struct sway_node *node; |
33 | union { | 33 | union { |
34 | struct sway_output_state *output_state; | 34 | struct sway_output_state output_state; |
35 | struct sway_workspace_state *workspace_state; | 35 | struct sway_workspace_state workspace_state; |
36 | struct sway_container_state *container_state; | 36 | struct sway_container_state container_state; |
37 | }; | 37 | }; |
38 | uint32_t serial; | 38 | uint32_t serial; |
39 | }; | 39 | }; |
40 | 40 | ||
41 | static struct sway_transaction *transaction_create() { | 41 | static struct sway_transaction *transaction_create(void) { |
42 | struct sway_transaction *transaction = | 42 | struct sway_transaction *transaction = |
43 | calloc(1, sizeof(struct sway_transaction)); | 43 | calloc(1, sizeof(struct sway_transaction)); |
44 | if (!sway_assert(transaction, "Unable to allocate transaction")) { | 44 | if (!sway_assert(transaction, "Unable to allocate transaction")) { |
@@ -86,14 +86,7 @@ static void transaction_destroy(struct sway_transaction *transaction) { | |||
86 | 86 | ||
87 | static void copy_output_state(struct sway_output *output, | 87 | static void copy_output_state(struct sway_output *output, |
88 | struct sway_transaction_instruction *instruction) { | 88 | struct sway_transaction_instruction *instruction) { |
89 | struct sway_output_state *state = | 89 | struct sway_output_state *state = &instruction->output_state; |
90 | calloc(1, sizeof(struct sway_output_state)); | ||
91 | if (!state) { | ||
92 | wlr_log(WLR_ERROR, "Could not allocate output state"); | ||
93 | return; | ||
94 | } | ||
95 | instruction->output_state = state; | ||
96 | |||
97 | state->workspaces = create_list(); | 90 | state->workspaces = create_list(); |
98 | list_cat(state->workspaces, output->workspaces); | 91 | list_cat(state->workspaces, output->workspaces); |
99 | 92 | ||
@@ -102,13 +95,7 @@ static void copy_output_state(struct sway_output *output, | |||
102 | 95 | ||
103 | static void copy_workspace_state(struct sway_workspace *ws, | 96 | static void copy_workspace_state(struct sway_workspace *ws, |
104 | struct sway_transaction_instruction *instruction) { | 97 | struct sway_transaction_instruction *instruction) { |
105 | struct sway_workspace_state *state = | 98 | struct sway_workspace_state *state = &instruction->workspace_state; |
106 | calloc(1, sizeof(struct sway_workspace_state)); | ||
107 | if (!state) { | ||
108 | wlr_log(WLR_ERROR, "Could not allocate workspace state"); | ||
109 | return; | ||
110 | } | ||
111 | instruction->workspace_state = state; | ||
112 | 99 | ||
113 | state->fullscreen = ws->fullscreen; | 100 | state->fullscreen = ws->fullscreen; |
114 | state->x = ws->x; | 101 | state->x = ws->x; |
@@ -138,13 +125,7 @@ static void copy_workspace_state(struct sway_workspace *ws, | |||
138 | 125 | ||
139 | static void copy_container_state(struct sway_container *container, | 126 | static void copy_container_state(struct sway_container *container, |
140 | struct sway_transaction_instruction *instruction) { | 127 | struct sway_transaction_instruction *instruction) { |
141 | struct sway_container_state *state = | 128 | struct sway_container_state *state = &instruction->container_state; |
142 | calloc(1, sizeof(struct sway_container_state)); | ||
143 | if (!state) { | ||
144 | wlr_log(WLR_ERROR, "Could not allocate container state"); | ||
145 | return; | ||
146 | } | ||
147 | instruction->container_state = state; | ||
148 | 129 | ||
149 | state->layout = container->layout; | 130 | state->layout = container->layout; |
150 | state->con_x = container->x; | 131 | state->con_x = container->x; |
@@ -301,15 +282,15 @@ static void transaction_apply(struct sway_transaction *transaction) { | |||
301 | case N_ROOT: | 282 | case N_ROOT: |
302 | break; | 283 | break; |
303 | case N_OUTPUT: | 284 | case N_OUTPUT: |
304 | apply_output_state(node->sway_output, instruction->output_state); | 285 | apply_output_state(node->sway_output, &instruction->output_state); |
305 | break; | 286 | break; |
306 | case N_WORKSPACE: | 287 | case N_WORKSPACE: |
307 | apply_workspace_state(node->sway_workspace, | 288 | apply_workspace_state(node->sway_workspace, |
308 | instruction->workspace_state); | 289 | &instruction->workspace_state); |
309 | break; | 290 | break; |
310 | case N_CONTAINER: | 291 | case N_CONTAINER: |
311 | apply_container_state(node->sway_container, | 292 | apply_container_state(node->sway_container, |
312 | instruction->container_state); | 293 | &instruction->container_state); |
313 | break; | 294 | break; |
314 | } | 295 | } |
315 | 296 | ||
@@ -335,7 +316,7 @@ static bool transaction_same_nodes(struct sway_transaction *a, | |||
335 | return true; | 316 | return true; |
336 | } | 317 | } |
337 | 318 | ||
338 | static void transaction_progress_queue() { | 319 | static void transaction_progress_queue(void) { |
339 | if (!server.transactions->length) { | 320 | if (!server.transactions->length) { |
340 | return; | 321 | return; |
341 | } | 322 | } |
@@ -390,7 +371,7 @@ static bool should_configure(struct sway_node *node, | |||
390 | return false; | 371 | return false; |
391 | } | 372 | } |
392 | struct sway_container_state *cstate = &node->sway_container->current; | 373 | struct sway_container_state *cstate = &node->sway_container->current; |
393 | struct sway_container_state *istate = instruction->container_state; | 374 | struct sway_container_state *istate = &instruction->container_state; |
394 | #ifdef HAVE_XWAYLAND | 375 | #ifdef HAVE_XWAYLAND |
395 | // Xwayland views are position-aware and need to be reconfigured | 376 | // Xwayland views are position-aware and need to be reconfigured |
396 | // when their position changes. | 377 | // when their position changes. |
@@ -418,10 +399,10 @@ static void transaction_commit(struct sway_transaction *transaction) { | |||
418 | struct sway_node *node = instruction->node; | 399 | struct sway_node *node = instruction->node; |
419 | if (should_configure(node, instruction)) { | 400 | if (should_configure(node, instruction)) { |
420 | instruction->serial = view_configure(node->sway_container->view, | 401 | instruction->serial = view_configure(node->sway_container->view, |
421 | instruction->container_state->view_x, | 402 | instruction->container_state.view_x, |
422 | instruction->container_state->view_y, | 403 | instruction->container_state.view_y, |
423 | instruction->container_state->view_width, | 404 | instruction->container_state.view_width, |
424 | instruction->container_state->view_height); | 405 | instruction->container_state.view_height); |
425 | ++transaction->num_waiting; | 406 | ++transaction->num_waiting; |
426 | 407 | ||
427 | // From here on we are rendering a saved buffer of the view, which | 408 | // From here on we are rendering a saved buffer of the view, which |
@@ -513,8 +494,8 @@ void transaction_notify_view_ready_by_size(struct sway_view *view, | |||
513 | int width, int height) { | 494 | int width, int height) { |
514 | struct sway_transaction_instruction *instruction = | 495 | struct sway_transaction_instruction *instruction = |
515 | view->container->node.instruction; | 496 | view->container->node.instruction; |
516 | if (instruction->container_state->view_width == width && | 497 | if (instruction->container_state.view_width == width && |
517 | instruction->container_state->view_height == height) { | 498 | instruction->container_state.view_height == height) { |
518 | set_instruction_ready(instruction); | 499 | set_instruction_ready(instruction); |
519 | } | 500 | } |
520 | } | 501 | } |