diff --git a/modules/dwl.c b/modules/dwl.c index a03a345..5fa1023 100644 --- a/modules/dwl.c +++ b/modules/dwl.c @@ -170,9 +170,12 @@ process_line(char *line, struct module *module) else if (index == 2) { if (strcmp(string, "title") == 0) { line_mode = LINE_MODE_TITLE; - /* cleanup title for every new batch */ + /* Update the title here, to avoid allocate and free memory on + * every iteration (the line is separated by spaces, then we + * join it again) a bit suboptimal, isn't it?) */ free(private->title); - private->title = NULL; + private->title = strdup(save_pointer); + break; } else if (strcmp(string, "fullscreen") == 0) line_mode = LINE_MODE_FULLSCREEN; else if (strcmp(string, "floating") == 0) @@ -222,20 +225,11 @@ process_line(char *line, struct module *module) dwl_tag->urgent = mask & urgent; } } - } else if (line_mode == LINE_MODE_TITLE) { - if (!private->title) { - private->title = strdup(string); - } else { - char *buf = NULL; - if (asprintf(&buf, "%s %s", private->title, string) < 0) { - LOG_ERRNO("asprintf"); - break; - } - free(private->title); - private->title = buf; - } } else switch (line_mode) { + case LINE_MODE_TITLE: + assert(false); /* unreachable */ + break; case LINE_MODE_FULLSCREEN: private->fullscreen = (strcmp(string, "0") != 0); break;