diff --git a/popup.c b/popup.c index 4ef1cc0a..c31977ba 100644 --- a/popup.c +++ b/popup.c @@ -104,6 +104,27 @@ static const struct menu_item popup_internal_menu_items[] = { { NULL, KEYC_NONE, NULL } }; +static void +popup_free(struct popup_data *pd) +{ + server_client_unref(pd->c); + + if (pd->job != NULL) + job_free(pd->job); + input_free(pd->ictx); + + free(pd->or[0].ranges); + free(pd->or[1].ranges); + free(pd->r.ranges); + screen_free(&pd->s); + colour_palette_free(&pd->palette); + + free(pd->title); + free(pd->style); + free(pd->border_style); + free(pd); +} + static void popup_reapply_styles(struct popup_data *pd) { @@ -344,22 +365,8 @@ popup_free_cb(struct client *c, void *data) cmdq_get_client(item)->retval = pd->status; cmdq_continue(item); } - server_client_unref(pd->c); - if (pd->job != NULL) - job_free(pd->job); - input_free(pd->ictx); - - free(pd->or[0].ranges); - free(pd->or[1].ranges); - free(pd->r.ranges); - screen_free(&pd->s); - colour_palette_free(&pd->palette); - - free(pd->title); - free(pd->style); - free(pd->border_style); - free(pd); + popup_free(pd); } static void @@ -858,6 +865,10 @@ popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, pd->job = job_run(shellcmd, argc, argv, env, s, cwd, popup_job_update_cb, popup_job_complete_cb, NULL, pd, JOB_NOWAIT|JOB_PTY|JOB_KEEPWRITE|JOB_DEFAULTSHELL, jx, jy); + if (pd->job == NULL) { + popup_free(pd); + return (-1); + } pd->ictx = input_init(NULL, job_get_event(pd->job), &pd->palette, c); }