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
1=== modified file 'src/im-menu.c'
2--- src/im-menu.c 2013-08-21 02:03:18 +0000
3+++ src/im-menu.c 2013-11-19 10:37:47 +0000
4@@ -179,11 +179,17 @@
5
6 for (position = 1; position < g_menu_model_get_n_items(G_MENU_MODEL (priv->menu)) - 1; position++)
7 {
8- gchar * item_sort = NULL;
9+ gchar *item_sort;
10+
11 if (g_menu_model_get_item_attribute(G_MENU_MODEL(priv->menu), position, "x-messaging-menu-sort-string", "s", &item_sort))
12- if (g_utf8_collate(sort_string, item_sort) < 0)
13- break;
14- g_free(item_sort);
15+ {
16+ gint cmp;
17+
18+ cmp = g_utf8_collate(sort_string, item_sort);
19+ g_free (item_sort);
20+ if (cmp < 0)
21+ break;
22+ }
23 }
24
25 item = g_menu_item_new_section (NULL, section);

Subscribers

People subscribed via source and target branches