suggestion picker: a persistent layer to complement virtual keyboards like wvkbd
input: fix obvious memory leak
| -rw-r--r-- | keyboard.c | 6 | ||||
| -rw-r--r-- | keyboard.h | 2 | ||||
| -rw-r--r-- | main.c | 6 |
3 files changed, 8 insertions, 6 deletions
@@ -15,9 +15,9 @@ void kbd_init(struct kbd *kb) { fprintf(stderr, "Initializing keyboard\n"); - kb->suggs[0].label = "Hello"; - kb->suggs[1].label = "World"; - kb->suggs[2].label = "World"; + kb->suggs[0].label = strdup("Hello"); + kb->suggs[1].label = strdup("Sugar"); + kb->suggs[2].label = strdup("Pie"); kb->suggs[3].label = NULL; } @@ -24,7 +24,7 @@ struct clr_scheme { }; struct key { - const char *label; // primary label + char *label; // actual coordinates on the surface (pixels), will be computed automatically // for all keys uint32_t x, y, w, h; @@ -391,7 +391,7 @@ handle_input(FILE *fd, struct key *sugg) { char *l = line; for (i = 0; l[i+1]; i++) { if (l[i] == '\t') { - // free label? + free(key->label); key->label = strndup(l,i); l += i + 1; i = 0; @@ -400,8 +400,10 @@ handle_input(FILE *fd, struct key *sugg) { break; } } + free(key->label); key->label = strndup(l,i); - key+=sizeof(struct key*); + key++; + free(key->label); key->label = NULL; } |