=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd-load-buffer.c,v retrieving revision 1.44 retrieving revision 1.45 diff -u -r1.44 -r1.45 --- src/usr.bin/tmux/cmd-load-buffer.c 2016/10/14 22:14:22 1.44 +++ src/usr.bin/tmux/cmd-load-buffer.c 2016/10/16 17:55:14 1.45 @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-load-buffer.c,v 1.44 2016/10/14 22:14:22 nicm Exp $ */ +/* $OpenBSD: cmd-load-buffer.c,v 1.45 2016/10/16 17:55:14 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha @@ -46,17 +46,24 @@ .exec = cmd_load_buffer_exec }; +struct cmd_load_buffer_data { + struct cmd_q *cmdq; + char *bufname; +}; + static enum cmd_retval cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq) { - struct args *args = self->args; - struct client *c = cmdq->client; - struct session *s; - FILE *f; - const char *path, *bufname, *cwd; - char *pdata, *new_pdata, *cause, *file, resolved[PATH_MAX]; - size_t psize; - int ch, error; + struct args *args = self->args; + struct cmd_load_buffer_data *cdata; + struct client *c = cmdq->client; + struct session *s; + FILE *f; + const char *path, *bufname, *cwd; + char *pdata, *new_pdata, *cause, *file; + char resolved[PATH_MAX]; + size_t psize; + int ch, error; bufname = NULL; if (args_has(args, 'b')) @@ -64,8 +71,12 @@ path = args->argv[0]; if (strcmp(path, "-") == 0) { + cdata = xcalloc(1, sizeof *cdata); + cdata->cmdq = cmdq; + cdata->bufname = xstrdup(bufname); + error = server_set_stdin_callback(c, cmd_load_buffer_callback, - (void *)bufname, &cause); + cdata, &cause); if (error != 0) { cmdq_error(cmdq, "%s: %s", path, cause); free(cause); @@ -136,9 +147,9 @@ static void cmd_load_buffer_callback(struct client *c, int closed, void *data) { - const char *bufname = data; - char *pdata, *cause, *saved; - size_t psize; + struct cmd_load_buffer_data *cdata = data; + char *pdata, *cause, *saved; + size_t psize; if (!closed) return; @@ -146,7 +157,7 @@ server_client_unref(c); if (c->flags & CLIENT_DEAD) - return; + goto out; psize = EVBUFFER_LENGTH(c->stdin_data); if (psize == 0 || (pdata = malloc(psize + 1)) == NULL) @@ -156,7 +167,7 @@ pdata[psize] = '\0'; evbuffer_drain(c->stdin_data, psize); - if (paste_set(pdata, psize, bufname, &cause) != 0) { + if (paste_set(pdata, psize, cdata->bufname, &cause) != 0) { /* No context so can't use server_client_msg_error. */ if (~c->flags & CLIENT_UTF8) { saved = cause; @@ -168,7 +179,9 @@ free(pdata); free(cause); } - out: - cmdq_continue(c->cmdq); + cdata->cmdq->flags &= ~CMD_Q_WAITING; + + free(cdata->bufname); + free(cdata); }