Fix memory leak for battery tooltips Instead of returning a const string, that is fed into strdup, tooltip functions are now supposed to return allocated strings. This fixes a memory leak in the battery tooltip. This is used instead of simply freeing the memory in the battery tooltip function, since it also avoids a uselesss strdup().
Sebastian Reichel sre@ring0.de
8 files changed,
12 insertions(+),
11 deletions(-)
M
src/battery/battery.c
→
src/battery/battery.c
@@ -220,7 +220,7 @@ if (!battery_timeout)
battery_timeout = add_timeout(10, 30000, update_battery_tick, 0, &battery_timeout); } -const char* battery_get_tooltip(void* obj) { +char* battery_get_tooltip(void* obj) { #if defined(__linux) return linux_batteries_get_tooltip(); #else
M
src/battery/battery.h
→
src/battery/battery.h
@@ -97,7 +97,7 @@ #ifdef __linux
gboolean init_linux_batteries(); void free_linux_batteries(); void update_linux_batteries(enum chargestate *state, gint64 *energy_now, gint64 *energy_full, int *seconds); -const char* linux_batteries_get_tooltip(); +char* linux_batteries_get_tooltip(); #endif #endif
M
src/battery/linux.c
→
src/battery/linux.c
@@ -319,7 +319,7 @@ return g_strdup_printf("0 %c", unit);
} } -const char* linux_batteries_get_tooltip() { +char* linux_batteries_get_tooltip() { GList *l; GString *tooltip = g_string_new(""); gchar *result;
M
src/clock/clock.c
→
src/clock/clock.c
@@ -144,10 +144,10 @@ }
else return localtime(&time_clock.tv_sec); } -const char* clock_get_tooltip(void* obj) +char* clock_get_tooltip(void* obj) { strftime(buf_tooltip, sizeof(buf_tooltip), time_tooltip_format, clock_gettime_for_tz(time_tooltip_timezone)); - return buf_tooltip; + return strdup(buf_tooltip); } int time_format_needs_sec_ticks(char *time_format)
M
src/launcher/launcher.c
→
src/launcher/launcher.c
@@ -347,10 +347,10 @@ launcherIcon->area.width = launcherIcon->icon_size;
launcherIcon->area.height = launcherIcon->icon_size; } -const char* launcher_icon_get_tooltip_text(void *obj) +char* launcher_icon_get_tooltip_text(void *obj) { LauncherIcon *launcherIcon = (LauncherIcon*)obj; - return launcherIcon->icon_tooltip; + return strdup(launcherIcon->icon_tooltip); } void draw_launcher_icon(void *obj, cairo_t *c)
M
src/taskbar/task.c
→
src/taskbar/task.c
@@ -38,10 +38,10 @@
timeout* urgent_timeout; GSList* urgent_list; -const char* task_get_tooltip(void* obj) +char* task_get_tooltip(void* obj) { Task* t = obj; - return t->title; + return strdup(t->title); }
M
src/tooltip/tooltip.c
→
src/tooltip/tooltip.c
@@ -304,7 +304,7 @@ void tooltip_copy_text(Area* area)
{ free(g_tooltip.tooltip_text); if (area && area->_get_tooltip_text) - g_tooltip.tooltip_text = strdup(area->_get_tooltip_text(area)); + g_tooltip.tooltip_text = area->_get_tooltip_text(area); else g_tooltip.tooltip_text = NULL; g_tooltip.area = area;
M
src/util/area.h
→
src/util/area.h
@@ -91,7 +91,8 @@ int (*_resize)(void *obj);
// after pos/size changed, the rendering engine will call _on_change_layout(Area*) int on_changed; void (*_on_change_layout)(void *obj); - const char* (*_get_tooltip_text)(void *obj); + // returns allocated string, that must be free'd after usage + char* (*_get_tooltip_text)(void *obj); } Area; // on startup, initialize fixed pos/size