mirror of
https://github.com/swaywm/sway.git
synced 2025-01-31 05:06:45 +00:00
desktop/output: Add missing output config allocation checks
(cherry picked from commit f38719f575
)
This commit is contained in:
parent
6d4d41cd09
commit
958f69dbdd
|
@ -632,6 +632,10 @@ void handle_gamma_control_set_gamma(struct wl_listener *listener, void *data) {
|
||||||
static struct output_config *output_config_for_config_head(
|
static struct output_config *output_config_for_config_head(
|
||||||
struct wlr_output_configuration_head_v1 *config_head) {
|
struct wlr_output_configuration_head_v1 *config_head) {
|
||||||
struct output_config *oc = new_output_config(config_head->state.output->name);
|
struct output_config *oc = new_output_config(config_head->state.output->name);
|
||||||
|
if (!oc) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
oc->enabled = config_head->state.enabled;
|
oc->enabled = config_head->state.enabled;
|
||||||
if (!oc->enabled) {
|
if (!oc->enabled) {
|
||||||
return oc;
|
return oc;
|
||||||
|
@ -662,7 +666,8 @@ static void output_manager_apply(struct sway_server *server,
|
||||||
size_t configs_len = config->output_configs->length + wl_list_length(&cfg->heads);
|
size_t configs_len = config->output_configs->length + wl_list_length(&cfg->heads);
|
||||||
struct output_config **configs = calloc(configs_len, sizeof(*configs));
|
struct output_config **configs = calloc(configs_len, sizeof(*configs));
|
||||||
if (!configs) {
|
if (!configs) {
|
||||||
goto done;
|
sway_log(SWAY_ERROR, "Allocation failed");
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
size_t start_new_configs = config->output_configs->length;
|
size_t start_new_configs = config->output_configs->length;
|
||||||
for (size_t idx = 0; idx < start_new_configs; idx++) {
|
for (size_t idx = 0; idx < start_new_configs; idx++) {
|
||||||
|
@ -675,6 +680,10 @@ static void output_manager_apply(struct sway_server *server,
|
||||||
// Generate the configuration and store it as a temporary
|
// Generate the configuration and store it as a temporary
|
||||||
// config. We keep a record of it so we can remove it later.
|
// config. We keep a record of it so we can remove it later.
|
||||||
struct output_config *oc = output_config_for_config_head(config_head);
|
struct output_config *oc = output_config_for_config_head(config_head);
|
||||||
|
if (!oc) {
|
||||||
|
sway_log(SWAY_ERROR, "Allocation failed");
|
||||||
|
goto error_config;
|
||||||
|
}
|
||||||
configs[config_idx++] = oc;
|
configs[config_idx++] = oc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -682,6 +691,8 @@ static void output_manager_apply(struct sway_server *server,
|
||||||
// if any output configured for enablement fails to be enabled, even if it
|
// if any output configured for enablement fails to be enabled, even if it
|
||||||
// was not part of the config heads we were asked to configure.
|
// was not part of the config heads we were asked to configure.
|
||||||
ok = apply_output_configs(configs, configs_len, test_only, false);
|
ok = apply_output_configs(configs, configs_len, test_only, false);
|
||||||
|
|
||||||
|
error_config:
|
||||||
for (size_t idx = start_new_configs; idx < configs_len; idx++) {
|
for (size_t idx = start_new_configs; idx < configs_len; idx++) {
|
||||||
struct output_config *cfg = configs[idx];
|
struct output_config *cfg = configs[idx];
|
||||||
if (!test_only && ok) {
|
if (!test_only && ok) {
|
||||||
|
@ -692,7 +703,7 @@ static void output_manager_apply(struct sway_server *server,
|
||||||
}
|
}
|
||||||
free(configs);
|
free(configs);
|
||||||
|
|
||||||
done:
|
error:
|
||||||
if (ok) {
|
if (ok) {
|
||||||
wlr_output_configuration_v1_send_succeeded(cfg);
|
wlr_output_configuration_v1_send_succeeded(cfg);
|
||||||
if (server->delayed_modeset != NULL) {
|
if (server->delayed_modeset != NULL) {
|
||||||
|
@ -727,6 +738,11 @@ void handle_output_power_manager_set_mode(struct wl_listener *listener,
|
||||||
struct sway_output *output = event->output->data;
|
struct sway_output *output = event->output->data;
|
||||||
|
|
||||||
struct output_config *oc = new_output_config(output->wlr_output->name);
|
struct output_config *oc = new_output_config(output->wlr_output->name);
|
||||||
|
if (!oc) {
|
||||||
|
sway_log(SWAY_ERROR, "Allocation failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (event->mode) {
|
switch (event->mode) {
|
||||||
case ZWLR_OUTPUT_POWER_V1_MODE_OFF:
|
case ZWLR_OUTPUT_POWER_V1_MODE_OFF:
|
||||||
oc->power = 0;
|
oc->power = 0;
|
||||||
|
|
Loading…
Reference in a new issue