~emersion/mrsh

a6446d74e697be64869eec9ed67496649c137ae0 — emersion 3 years ago 2f4c97c
Fix memory leaks in main.c
2 files changed, 4 insertions(+), 2 deletions(-)

M buffer.c
M main.c
M buffer.c => buffer.c +1 -0
@@ 63,5 63,6 @@ char *mrsh_buffer_steal(struct mrsh_buffer *buf) {

void mrsh_buffer_finish(struct mrsh_buffer *buf) {
	free(buf->data);
	buf->data = NULL;
	buf->cap = buf->len = 0;
}

M main.c => main.c +3 -2
@@ 128,12 128,12 @@ int main(int argc, char *argv[]) {
			}
			char *line = NULL;
			size_t n = interactive_next(&state, &line, prompt);
			free(prompt);
			if (!line) {
				state.exit = EXIT_FAILURE;
				continue;
			}
			mrsh_buffer_append(&read_buffer, line, n);
			free(prompt);
			free(line);
			parser = mrsh_parser_create_from_buffer(
					read_buffer.data, read_buffer.len);


@@ 171,7 171,7 @@ int main(int argc, char *argv[]) {
				mrsh_run_program(&state, prog);
			}
			mrsh_program_destroy(prog);
			mrsh_buffer_steal(&read_buffer);
			mrsh_buffer_finish(&read_buffer);
		}
		if (state.interactive) {
			mrsh_parser_destroy(parser);


@@ 184,6 184,7 @@ int main(int argc, char *argv[]) {
		mrsh_parser_destroy(parser);
	}

	mrsh_buffer_finish(&read_buffer);
	mrsh_state_finish(&state);
	fclose(state.input);