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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user