Small memory leaks fixed and other cleanups.

This commit is contained in:
Dave Davenport 2023-04-21 12:50:55 +02:00
parent 4de46aece6
commit b68f64ccee
8 changed files with 26 additions and 15 deletions

View file

@ -243,8 +243,9 @@ static char *combi_mgrv(const Mode *sw, unsigned int selected_line, int *state,
*state |= MARKUP;
}
retv = helper_string_replace_if_exists(
config.combi_display_format, "{mode}", dname, "{text}", str, NULL);
retv = helper_string_replace_if_exists(config.combi_display_format,
"{mode}", dname, "{text}", str,
(char *)0);
g_free(str);
if (attr_list != NULL) {

View file

@ -388,14 +388,14 @@ static gchar *dmenu_format_output_string(const DmenuModePrivateData *pd,
}
}
for (uint32_t i = 0; pd->columns && pd->columns[i]; i++) {
unsigned int index =
unsigned int col_index =
(unsigned int)g_ascii_strtoull(pd->columns[i], NULL, 10);
if (index <= ns && index > 0) {
if (col_index <= ns && col_index > 0) {
if (i == 0) {
g_string_append(str_retv, splitted[index - 1]);
g_string_append(str_retv, splitted[col_index - 1]);
} else {
g_string_append_c(str_retv, '\t');
g_string_append(str_retv, splitted[index - 1]);
g_string_append(str_retv, splitted[col_index - 1]);
}
}
}

View file

@ -1323,11 +1323,12 @@ static char *_get_display_value(const Mode *sw, unsigned int selected_line,
char *retv = helper_string_replace_if_exists(
config.drun_display_format, "{generic}", egn, "{name}", en, "{comment}",
ec, "{exec}", dr->exec, "{categories}", cats, "{keywords}", keywords,
NULL);
(char *)0);
g_free(egn);
g_free(en);
g_free(ec);
g_free(cats);
g_free(keywords);
return retv;
}

View file

@ -868,7 +868,7 @@ static void window_mode_destroy(Mode *sw) {
}
struct arg {
const WindowModePrivateData *pd;
client *c;
const client *c;
};
static void helper_eval_add_str(GString *str, const char *input, int l,
@ -932,7 +932,7 @@ static gboolean helper_eval_cb(const GMatchInfo *info, GString *str,
return FALSE;
}
static char *_generate_display_string(const WindowModePrivateData *pd,
client *c) {
const client *c) {
struct arg d = {pd, c};
char *res = g_regex_replace_eval(pd->window_regex, config.window_format, -1,
0, 0, helper_eval_cb, &d, NULL);
@ -943,7 +943,7 @@ static char *_get_display_value(const Mode *sw, unsigned int selected_line,
int *state, G_GNUC_UNUSED GList **list,
int get_entry) {
WindowModePrivateData *rmpd = mode_get_private_data(sw);
client *c = window_client(rmpd, rmpd->ids->array[selected_line]);
const client *c = window_client(rmpd, rmpd->ids->array[selected_line]);
if (c == NULL) {
return get_entry ? g_strdup("Window has vanished") : NULL;
}

View file

@ -350,6 +350,7 @@ static void rofi_icon_fetcher_worker(thread_state *sdata,
const char *suf = strrchr(icon_path, '.');
if (suf == NULL) {
sentry->query_done = TRUE;
g_free(icon_path_);
rofi_view_reload();
return;
}

View file

@ -485,9 +485,9 @@ static void rofi_view_reload_message_bar(RofiViewState *state) {
GList *iter = g_list_first(list_of_warning_msgs);
int index = 0;
for (; iter != NULL && index < 2; iter = g_list_next(iter)) {
GString *msg = (GString *)(iter->data);
GString *in_msg = (GString *)(iter->data);
g_string_append(emesg, "\n\n");
g_string_append(emesg, msg->str);
g_string_append(emesg, in_msg->str);
index++;
}
if (g_list_length(iter) > 1) {
@ -971,6 +971,9 @@ static void input_history_save(void) {
}
// Cleanups.
if (CacheState.entry_history != NULL) {
for (ssize_t i = 0; i < CacheState.entry_history_length; i++) {
g_free(CacheState.entry_history[i].string);
}
g_free(CacheState.entry_history);
CacheState.entry_history = NULL;
CacheState.entry_history_length = 0;

View file

@ -174,7 +174,7 @@ static void listview_add_widget(listview *lv, _listview_row *row, widget *wid,
} else if (strcasecmp(label, "element-text") == 0) {
row->textbox =
textbox_create(WIDGET(wid), WIDGET_TYPE_TEXTBOX_TEXT, "element-text",
TB_AUTOHEIGHT , NORMAL, "DDD", 0, 0);
TB_AUTOHEIGHT, NORMAL, "DDD", 0, 0);
textbox_set_ellipsize(row->textbox, lv->emode);
box_add((box *)wid, WIDGET(row->textbox), TRUE);
} else if (strcasecmp(label, "element-index") == 0) {
@ -617,7 +617,7 @@ void listview_set_selected(listview *lv, unsigned int selected) {
if (lv->sc_callback) {
lv->sc_callback(lv, lv->selected, lv->sc_udata);
}
} else if (lv->req_elements == 0) {
} else {
if (lv->sc_callback) {
lv->sc_callback(lv, UINT32_MAX, lv->sc_udata);
}

View file

@ -365,7 +365,12 @@ char *textbox_get_text(const textbox *tb) {
}
return g_strdup(tb->text);
}
int textbox_get_cursor(const textbox *tb) { return tb->cursor; }
int textbox_get_cursor(const textbox *tb) {
if (tb) {
return tb->cursor;
}
return 0;
}
// set the default text to display
void textbox_text(textbox *tb, const char *text) {
if (tb == NULL) {