Skip to content

Commit

Permalink
Fix setlayout + IPC fd leak (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvaiya committed Aug 12, 2022
1 parent e63ceec commit ae51918
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
46 changes: 30 additions & 16 deletions src/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ static int cache_get(struct keyboard *kbd, uint8_t code,
return -1;
}

static void reset_keystate(struct keyboard *kbd)
{
size_t i;

for (i = 0; i < 256; i++) {
if (kbd->keystate[i]) {
vkbd_send_key(vkbd, i, 0);
kbd->keystate[i] = 0;
}
}

}

static void send_key(struct keyboard *kbd, uint8_t code, uint8_t pressed)
{
Expand Down Expand Up @@ -305,21 +317,6 @@ static void update_leds(struct keyboard *kbd)
set_led(1, active);
}

static void setlayout(struct keyboard *kbd, uint8_t idx)
{
/* Only only layout may be active at a time */
size_t i;
for (i = 0; i < kbd->config.nr_layers; i++) {
struct layer *layer = &kbd->config.layers[i];

if (layer->type == LT_LAYOUT)
kbd->layer_state[i].active = 0;
}

kbd->layer_state[idx].activation_time = get_time();
kbd->layer_state[idx].active = 1;
}

static void deactivate_layer(struct keyboard *kbd, int idx)
{
dbg("Deactivating layer %s", kbd->config.layers[idx].name);
Expand Down Expand Up @@ -400,9 +397,26 @@ static void clear(struct keyboard *kbd)
kbd->oneshot_latch = 0;
kbd->active_macro = NULL;

update_mods(kbd, -1, 0);
reset_keystate(kbd);
}

static void setlayout(struct keyboard *kbd, uint8_t idx)
{
clear(kbd);
/* Only only layout may be active at a time */
size_t i;
for (i = 0; i < kbd->config.nr_layers; i++) {
struct layer *layer = &kbd->config.layers[i];

if (layer->type == LT_LAYOUT)
kbd->layer_state[i].active = 0;
}

kbd->layer_state[idx].activation_time = 1;
kbd->layer_state[idx].active = 1;
}


static long process_descriptor(struct keyboard *kbd, uint8_t code,
struct descriptor *d, int dl,
int pressed)
Expand Down
2 changes: 2 additions & 0 deletions src/keyd.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ static void process_client_connection(int con)
default:
break;
}

close(con);
}

static int loop(int monitor_mode)
Expand Down

0 comments on commit ae51918

Please sign in to comment.