~earboxer/suggpicker

d04f7e07d4a5278e8e8530925e2852b591d6e37b — Zach DeCook 2 years ago da3ce83
input: fix obvious memory leak
3 files changed, 8 insertions(+), 6 deletions(-)

M keyboard.c
M keyboard.h
M main.c
M keyboard.c => keyboard.c +3 -3
@@ 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;
}


M keyboard.h => keyboard.h +1 -1
@@ 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;

M main.c => main.c +4 -2
@@ 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;
	}