From 5f07da6227cecf3d66aa9f28579f48396373d9e4 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 31 Jul 2018 13:06:44 +0000 Subject: [PATCH] Do not leak path or use it after free. --- cmd-load-buffer.c | 4 +++- cmd-save-buffer.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd-load-buffer.c b/cmd-load-buffer.c index 6920a21a..b7c299b7 100644 --- a/cmd-load-buffer.c +++ b/cmd-load-buffer.c @@ -85,7 +85,7 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item) error = server_set_stdin_callback(c, cmd_load_buffer_callback, cdata, &cause); if (error != 0) { - cmdq_error(item, "%s: %s", path, cause); + cmdq_error(item, "-: %s", cause); free(cause); return (CMD_RETURN_ERROR); } @@ -93,6 +93,8 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item) } file = server_client_get_path(c, path); + free(path); + f = fopen(file, "rb"); if (f == NULL) { cmdq_error(item, "%s: %s", file, strerror(errno)); diff --git a/cmd-save-buffer.c b/cmd-save-buffer.c index 6d5ddafd..f6ac93a6 100644 --- a/cmd-save-buffer.c +++ b/cmd-save-buffer.c @@ -106,6 +106,8 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item) flags = "ab"; file = server_client_get_path(c, path); + free(path); + f = fopen(file, flags); if (f == NULL) { cmdq_error(item, "%s: %s", file, strerror(errno)); @@ -122,7 +124,6 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item) fclose(f); free(file); - free(path); return (CMD_RETURN_NORMAL);