mirror of
https://github.com/tmux/tmux.git
synced 2025-09-03 14:27:09 +00:00
Add functions to allocate and free command contexts rather than doing it all on
the stack.
This commit is contained in:
35
cfg.c
35
cfg.c
@ -80,7 +80,7 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
|
||||
char *buf, *copy, *line, *cause;
|
||||
size_t len, oldlen;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd_ctx ctx;
|
||||
struct cmd_ctx *ctx;
|
||||
enum cmd_retval retval;
|
||||
|
||||
if ((f = fopen(path, "rb")) == NULL) {
|
||||
@ -90,6 +90,21 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
|
||||
|
||||
cfg_references++;
|
||||
|
||||
ctx = cmd_get_ctx();
|
||||
if (ctxin == NULL) {
|
||||
ctx->msgdata = NULL;
|
||||
ctx->curclient = NULL;
|
||||
ctx->cmdclient = NULL;
|
||||
} else {
|
||||
ctx->msgdata = ctxin->msgdata;
|
||||
ctx->curclient = ctxin->curclient;
|
||||
ctx->cmdclient = ctxin->cmdclient;
|
||||
}
|
||||
|
||||
ctx->error = cfg_error;
|
||||
ctx->print = cfg_print;
|
||||
ctx->info = cfg_print;
|
||||
|
||||
n = 0;
|
||||
line = NULL;
|
||||
retval = CMD_RETURN_NORMAL;
|
||||
@ -146,22 +161,8 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
|
||||
if (cmdlist == NULL)
|
||||
continue;
|
||||
|
||||
if (ctxin == NULL) {
|
||||
ctx.msgdata = NULL;
|
||||
ctx.curclient = NULL;
|
||||
ctx.cmdclient = NULL;
|
||||
} else {
|
||||
ctx.msgdata = ctxin->msgdata;
|
||||
ctx.curclient = ctxin->curclient;
|
||||
ctx.cmdclient = ctxin->cmdclient;
|
||||
}
|
||||
|
||||
ctx.error = cfg_error;
|
||||
ctx.print = cfg_print;
|
||||
ctx.info = cfg_print;
|
||||
|
||||
cfg_cause = NULL;
|
||||
switch (cmd_list_exec(cmdlist, &ctx)) {
|
||||
switch (cmd_list_exec(cmdlist, ctx)) {
|
||||
case CMD_RETURN_YIELD:
|
||||
if (retval != CMD_RETURN_ATTACH)
|
||||
retval = CMD_RETURN_YIELD;
|
||||
@ -186,6 +187,8 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
cmd_free_ctx(ctx);
|
||||
|
||||
cfg_references--;
|
||||
|
||||
return (retval);
|
||||
|
Reference in New Issue
Block a user