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().
This commit is contained in:
parent
cbd52d1a48
commit
edad9bb7f5
8 changed files with 12 additions and 11 deletions
|
@ -220,7 +220,7 @@ void init_battery()
|
|||
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
|
||||
|
|
|
@ -97,7 +97,7 @@ void battery_action(int button);
|
|||
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
|
||||
|
|
|
@ -319,7 +319,7 @@ static gchar* power_human_readable(struct psy_battery *bat) {
|
|||
}
|
||||
}
|
||||
|
||||
const char* linux_batteries_get_tooltip() {
|
||||
char* linux_batteries_get_tooltip() {
|
||||
GList *l;
|
||||
GString *tooltip = g_string_new("");
|
||||
gchar *result;
|
||||
|
|
|
@ -144,10 +144,10 @@ struct tm* clock_gettime_for_tz(const char* timezone) {
|
|||
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)
|
||||
|
|
|
@ -347,10 +347,10 @@ void launcher_icon_on_change_layout(void *obj)
|
|||
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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -91,7 +91,8 @@ typedef struct {
|
|||
// 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
|
||||
|
|
Loading…
Reference in a new issue