After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 782083 - toolbar: Don't leak previous allocations
toolbar: Don't leak previous allocations
Status: RESOLVED FIXED
Product: nautilus
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: Nautilus Maintainers
Nautilus Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-05-02 17:15 UTC by Mohammed Sadiq
Modified: 2017-05-05 14:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
toolbar: Don't leak previous allocations (1.36 KB, patch)
2017-05-02 17:15 UTC, Mohammed Sadiq
none Details | Review
toolbar: Don't leak previous allocations (1.39 KB, patch)
2017-05-02 17:37 UTC, Mohammed Sadiq
none Details | Review
pre-patch screencast (231.03 KB, video/webm)
2017-05-03 14:14 UTC, Ernestas Kulik
  Details
post-patch screencast (224.37 KB, video/webm)
2017-05-03 14:14 UTC, Ernestas Kulik
  Details
toolbar: Don't leak previous allocations (1.46 KB, patch)
2017-05-03 14:57 UTC, Mohammed Sadiq
committed Details | Review

Description Mohammed Sadiq 2017-05-02 17:15:31 UTC
.
Comment 1 Mohammed Sadiq 2017-05-02 17:15:40 UTC
Created attachment 350899 [details] [review]
toolbar: Don't leak previous allocations

When undo_active/redo_active is FALSE, undo_label/redo_label
was getting overwritten irrespective of whether they were
NULL or not.

Let those values be updated only when they are NULL and thus
avoid possible leaks.
Comment 2 Ernestas Kulik 2017-05-02 17:18:00 UTC
Review of attachment 350899 [details] [review]:

Awesome, thanks!

::: src/nautilus-toolbar.c
@@ +855,3 @@
      */
+
+    if (undo_label == NULL)

Braces and four-space indents.
Comment 3 Mohammed Sadiq 2017-05-02 17:37:39 UTC
Created attachment 350902 [details] [review]
toolbar: Don't leak previous allocations

When undo_active/redo_active is FALSE, undo_label/redo_label
was getting overwritten irrespective of whether they were
NULL or not.

Let those values be updated only when they are NULL and thus
avoid possible leaks.

Sorry, my editor defaults to GNU style.
Comment 4 Ernestas Kulik 2017-05-02 17:54:18 UTC
Review of attachment 350902 [details] [review]:

Discussed to oblivion on IRC, LGTM.
Comment 5 Ernestas Kulik 2017-05-03 10:32:57 UTC
Comment on attachment 350902 [details] [review]
toolbar: Don't leak previous allocations

Ah, sorry, this breaks the logic of the code.
Comment 6 Ernestas Kulik 2017-05-03 11:52:26 UTC
Review of attachment 350902 [details] [review]:

::: src/nautilus-toolbar.c
@@ -854,3 @@
     /* Set the label of the undo and redo menu items, and activate them appropriately
      */
-    undo_label = undo_active && undo_label != NULL ? undo_label : g_strdup (_("_Undo"));

What needs to happen here is for undo_label to be set to “Undo” if !undo_active. So you need to figure out the deallocation in that case.

@@ +857,3 @@
+    {
+        undo_label = g_strdup (_("_Undo"));
+    }

If you test the code, you’ll see how it breaks.
Comment 7 Ernestas Kulik 2017-05-03 14:14:16 UTC
Created attachment 350984 [details]
pre-patch screencast
Comment 8 Ernestas Kulik 2017-05-03 14:14:44 UTC
Created attachment 350985 [details]
post-patch screencast
Comment 9 Mohammed Sadiq 2017-05-03 14:57:14 UTC
Created attachment 350989 [details] [review]
toolbar: Don't leak previous allocations

When undo_active/redo_active is FALSE, undo_label/redo_label
was getting overwritten irrespective of whether they were
NULL or not.

Let the label values be freed incase they are updated.
Comment 10 Ernestas Kulik 2017-05-03 15:50:13 UTC
Review of attachment 350989 [details] [review]:

Okay, for real this time. :)
Comment 11 Ernestas Kulik 2017-05-05 14:15:25 UTC
Attachment 350989 [details] pushed as ec52282 - toolbar: Don't leak previous allocations