Merge lp:~larsu/indicator-messages/fix-leak into lp:indicator-messages/14.04

Proposed by Lars Karlitski
Status: Merged
Approved by: Charles Kerr
Approved revision: 398
Merged at revision: 397
Proposed branch: lp:~larsu/indicator-messages/fix-leak
Merge into: lp:indicator-messages/14.04
Diff against target: 25 lines (+10/-4)
1 file modified
src/im-menu.c (+10/-4)
To merge this branch: bzr merge lp:~larsu/indicator-messages/fix-leak
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Ted Gould (community) Approve
Review via email: mp+194824@code.launchpad.net

Description of the change

im-menu: fix leak

To post a comment you must log in.
Revision history for this message
Ted Gould (ted) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

This is a nice find, but the fix is slightly wrong:

if g_menu_model_get_item_attribute() returns true, we need to call "g_free (item_sort);" no matter what g_utf8_collate() returns.

Maybe something like

  if (g_menu_model_get_item_attribute (...)
    {
      gint collated = g_utf8_collate (sort_string, item_sort);
      g_free (item_sort);
      if (collated < 0)
        break;
    }

review: Needs Fixing
Revision history for this message
Lars Karlitski (larsu) wrote :

> This is a nice find, but the fix is slightly wrong:
>
> if g_menu_model_get_item_attribute() returns true, we need to call "g_free
> (item_sort);" no matter what g_utf8_collate() returns.

The fix is correct. g_free() is always called after the condition (item_sort is explicitly set to NULL). The problem this patch solves is that g_free() wasn't called when breaking out of the surrounding loop.

I'll change it anyway because your solution reads better. Thanks!

398. By Lars Karlitski

im_menu_insert: make sorting logic more readable

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Ah, sorry about that. :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/im-menu.c'
--- src/im-menu.c 2013-08-21 02:03:18 +0000
+++ src/im-menu.c 2013-11-19 10:37:47 +0000
@@ -179,11 +179,17 @@
179179
180 for (position = 1; position < g_menu_model_get_n_items(G_MENU_MODEL (priv->menu)) - 1; position++)180 for (position = 1; position < g_menu_model_get_n_items(G_MENU_MODEL (priv->menu)) - 1; position++)
181 {181 {
182 gchar * item_sort = NULL;182 gchar *item_sort;
183
183 if (g_menu_model_get_item_attribute(G_MENU_MODEL(priv->menu), position, "x-messaging-menu-sort-string", "s", &item_sort))184 if (g_menu_model_get_item_attribute(G_MENU_MODEL(priv->menu), position, "x-messaging-menu-sort-string", "s", &item_sort))
184 if (g_utf8_collate(sort_string, item_sort) < 0)185 {
185 break;186 gint cmp;
186 g_free(item_sort);187
188 cmp = g_utf8_collate(sort_string, item_sort);
189 g_free (item_sort);
190 if (cmp < 0)
191 break;
192 }
187 }193 }
188194
189 item = g_menu_item_new_section (NULL, section);195 item = g_menu_item_new_section (NULL, section);

Subscribers

People subscribed via source and target branches