-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
battstat: call up_client_get_devices once to avoid mem leak #443
base: master
Are you sure you want to change the base?
Changes from 2 commits
2991bc7
a73baf2
591ebcc
135c7c4
be43872
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,8 @@ static void (*status_updated_callback) (void); | |
*/ | ||
static gboolean status_update_scheduled; | ||
|
||
static GPtrArray *devices; | ||
|
||
static gboolean | ||
update_status_idle (gpointer junk) | ||
{ | ||
|
@@ -83,9 +85,6 @@ battstat_upower_initialise (void (*callback) (void)) | |
int i, num; | ||
|
||
status_updated_callback = callback; | ||
#if UP_CHECK_VERSION (0, 99, 0) | ||
GPtrArray *devices; | ||
#endif | ||
|
||
if( upc != NULL ) | ||
return g_strdup( "Already initialised!" ); | ||
|
@@ -101,7 +100,6 @@ battstat_upower_initialise (void (*callback) (void)) | |
if (!devices) { | ||
goto error_shutdownclient; | ||
} | ||
g_ptr_array_unref(devices); | ||
#else | ||
if (! up_client_enumerate_devices_sync( upc, cancellable, &gerror ) ) { | ||
sprintf(error_str, "Unable to enumerate upower devices: %s\n", gerror->message); | ||
|
@@ -133,6 +131,7 @@ battstat_upower_cleanup( void ) | |
if( upc == NULL ) | ||
return; | ||
|
||
alwilson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
g_object_unref( devices ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd re-do the code here to put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is my first time touching GTK, so I'll take your word on that. 😋 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is my first time reviewing GTK, so best of luck. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You must be glad that I at least have learned some C |
||
g_object_unref( upc ); | ||
upc = NULL; | ||
} | ||
|
@@ -154,9 +153,6 @@ battstat_upower_cleanup( void ) | |
void | ||
battstat_upower_get_battery_info( BatteryStatus *status ) | ||
{ | ||
|
||
GPtrArray *devices = up_client_get_devices( upc ); | ||
|
||
/* The calculation to get overall percentage power remaining is as follows: | ||
* | ||
* Sum( Current charges ) / Sum( Full Capacities ) | ||
|
@@ -259,7 +255,6 @@ battstat_upower_get_battery_info( BatteryStatus *status ) | |
status->on_ac_power = TRUE; | ||
status->charging = FALSE; | ||
|
||
g_ptr_array_unref( devices ); | ||
return; | ||
} | ||
|
||
|
@@ -326,8 +321,6 @@ battstat_upower_get_battery_info( BatteryStatus *status ) | |
/* These are simple and well-explained above. */ | ||
status->charging = charging; | ||
status->on_ac_power = on_ac_power; | ||
|
||
g_ptr_array_unref( devices ); | ||
} | ||
|
||
void | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If anyone wonders, removing
#if
is fine as the actual application for this happens below.Sharing the variable between functions would lead to eventual utilization of
up_client_get_devices
unconditionally anyway.