Merge lp:~jjardon/indicator-datetime/fix-836017 into lp:indicator-datetime/0.3

Proposed by Javier Jardón
Status: Merged
Merge reported by: Charles Kerr
Merged at revision: not available
Proposed branch: lp:~jjardon/indicator-datetime/fix-836017
Merge into: lp:indicator-datetime/0.3
Diff against target: 46 lines (+19/-9)
1 file modified
src/datetime-service.c (+19/-9)
To merge this branch: bzr merge lp:~jjardon/indicator-datetime/fix-836017
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
Javier Jardón (community) Needs Resubmitting
Andrea Cimitan (community) Needs Information
Review via email: mp+77932@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Andrea Cimitan (cimi) wrote :

Hi Javier! You need to free the GSlist *accounts_list with:

if (accounts_list)
  g_slist_free (accounts_list);

before setting it to NULL.

review: Needs Fixing
141. By Javier Jardón

datetime-service: Free accounts list in the correct place

Revision history for this message
Javier Jardón (jjardon) wrote :

Thanks for the review Andrea, Could you take a look to this new patch?

review: Needs Resubmitting
Revision history for this message
Andrea Cimitan (cimi) wrote :

It depends... if error is != NULL it enters the first if but not the second, so accounts_list is set to NULL and not free'd. Now, it could be that if error is != NULL then accounts_list is NULL and it does not need to be free'd, so your code is not leaking.
However, I'm not sure of that (that accounts_list is NULL and thus does not need to be free'd if error is != NULL), so in my ignorance I'd put the code as I wrote before, adding

if (accounts_list)
  g_slist_free (accounts_list);

before setting it to NULL in the first if.

If you're sure of my concern, go ahead, otherwise we might need to look at gconf code and see which GSList we can receive from gconf_client_get_list when error is not NULL.

review: Needs Information
142. By Javier Jardón

datetime-service: Be sure to free the returned list

Revision history for this message
Javier Jardón (jjardon) wrote :

Ok, lets be super-sure to free the possible returned list

review: Needs Resubmitting
Revision history for this message
Charles Kerr (charlesk) wrote :

1. we don't appear to use "error" except for testing for failure, and on failure list will be NULL anyway so that test is redundant. Let's remove the error variable altogether.

2. g_slist_free() is NULL-safe, so there "if (list != NULL)" test before g_slist_free(list) is unnecessary.

3. I think we're also leaking the "evo" variable in greeter mode.

What would you think about moving it to a standalone function like this:

static gboolean
calendar_app_is_usable (void)
{
        /* confirm that it's installed... */
        gchar *evo = g_find_program_in_path("evolution");
        if (evo == NULL)
                return FALSE;
        g_debug ("found evolution at '%s'", evo);
        g_free (evo);

        /* confirm that there's an account set up */
        GSList *accounts_list = gconf_client_get_list (gconf, "/apps/evolution/mail/accounts", GCONF_VALUE_STRING, NULL);
        g_debug ("found %u evolution accounts", g_slist_length(accounts_list));
        const gboolean is_configured = accounts_list != NULL;
        g_slist_free (accounts_list);
        return is_configured;
}

review: Needs Fixing
Revision history for this message
Charles Kerr (charlesk) wrote :

Javier, I'm going to move your code into the standalone function to fix the 'evo' memory leak and merge. I hope you don't mind this -- I want to make sure your fix gets in before the deadline.

review: Approve
Revision history for this message
Javier Jardón (jjardon) wrote :

Yeah, sure. I think is a good idea

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/datetime-service.c'
2--- src/datetime-service.c 2011-09-29 19:57:50 +0000
3+++ src/datetime-service.c 2011-10-04 19:24:25 +0000
4@@ -484,6 +484,8 @@
5 static gboolean
6 check_for_calendar (gpointer user_data)
7 {
8+ GError *error = NULL;
9+
10 g_return_val_if_fail (calendar != NULL, FALSE);
11
12 dbusmenu_menuitem_property_set_bool(date, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);
13@@ -494,16 +496,24 @@
14
15 g_signal_connect (G_OBJECT(date), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
16 G_CALLBACK (activate_cb), "evolution -c calendar");
17-
18- events_separator = dbusmenu_menuitem_new();
19- dbusmenu_menuitem_property_set(events_separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR);
20- dbusmenu_menuitem_child_add_position(root, events_separator, 2);
21- add_appointment = dbusmenu_menuitem_new();
22- dbusmenu_menuitem_property_set (add_appointment, DBUSMENU_MENUITEM_PROP_LABEL, _("Add Event…"));
23- dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);
24- g_signal_connect(G_OBJECT(add_appointment), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), "evolution -c calendar");
25- dbusmenu_menuitem_child_add_position (root, add_appointment, 3);
26
27+ GSList *accounts_list = gconf_client_get_list (gconf, "/apps/evolution/mail/accounts", GCONF_VALUE_STRING, &error);
28+ if (error != NULL) {
29+ g_debug("%s: Failed to get evolution mail accounts", G_STRFUNC);
30+ g_clear_error (&error);
31+ if (accounts_list)
32+ g_slist_free (accounts_list);
33+ } else if (accounts_list != NULL) {
34+ g_slist_free (accounts_list);
35+ events_separator = dbusmenu_menuitem_new();
36+ dbusmenu_menuitem_property_set(events_separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR);
37+ dbusmenu_menuitem_child_add_position(root, events_separator, 2);
38+ add_appointment = dbusmenu_menuitem_new();
39+ dbusmenu_menuitem_property_set (add_appointment, DBUSMENU_MENUITEM_PROP_LABEL, _("Add Event…"));
40+ dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);
41+ g_signal_connect(G_OBJECT(add_appointment), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), "evolution -c calendar");
42+ dbusmenu_menuitem_child_add_position (root, add_appointment, 3);
43+ }
44
45 if (g_settings_get_boolean(conf, SETTINGS_SHOW_EVENTS_S)) {
46 dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);

Subscribers

People subscribed via source and target branches